home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / packages / ps-print.el.z / ps-print.el
Encoding:
Text File  |  1998-05-21  |  106.1 KB  |  3,216 lines

  1. ;;; ps-print.el --- Jim's Pretty-Good PostScript Generator for Emacs 19.
  2.  
  3. ;; Copyright (C) 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
  4.  
  5. ;; Author:     Jim Thompson (was <thompson@wg2.waii.com>)
  6. ;; Maintainer: Jacques Duthen <duthen@club-internet.fr>
  7. ;; Keywords:   print, PostScript
  8. ;; Time-stamp: <97/01/29 23:21:25 tjchol01>
  9. ;; Version:    3.05
  10.  
  11. ;; 1997-12-03 Kyle Jones
  12. ;;   Hacked on ps-face-attributes a little for XEmacs
  13. ;;   Made it not specify foreground and background colors unless
  14. ;;   they are different from those of the default face.
  15. ;;   Previously foreground and background colors were specified
  16. ;;   if any property in the face differed from the default face.
  17.  
  18. (defconst ps-print-version "3.05"
  19.   "ps-print.el, v 3.05 <97/01/17 duthen>
  20.  
  21. Jack's last change version -- this file may have been edited as part of
  22. Emacs without changes to the version number.  When reporting bugs,
  23. please also report the version of Emacs, if any, that ps-print was
  24. distributed with.
  25.  
  26. Please send all bug fixes and enhancements to
  27.     Jacques Duthen <duthen@cegelec-red.fr>.
  28. ")
  29.  
  30. ;; This file is part of GNU Emacs.
  31.  
  32. ;; GNU Emacs is free software; you can redistribute it and/or modify
  33. ;; it under the terms of the GNU General Public License as published by
  34. ;; the Free Software Foundation; either version 2, or (at your option)
  35. ;; any later version.
  36.  
  37. ;; GNU Emacs is distributed in the hope that it will be useful,
  38. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  39. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  40. ;; GNU General Public License for more details.
  41.  
  42. ;; You should have received a copy of the GNU General Public License
  43. ;; along with GNU Emacs; see the file COPYING.  If not, write to the
  44. ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  45. ;; Boston, MA 02111-1307, USA.
  46.  
  47. ;; LCD Archive Entry:
  48. ;; ps-print|James C. Thompson|thompson@wg2.waii.com|
  49. ;; Jim's Pretty-Good PostScript Generator for Emacs 19 (ps-print)|
  50. ;; 26-Feb-1994|2.8|~/packages/ps-print.el|
  51.  
  52. ;; 3.05 [jack] <97/01/16 duthen>
  53. ;; Ben Wing <ben@666.com> took ps-print.el from the official 19.34
  54. ;; GNU distribution:
  55. ;; -rw-rw-r--  1 duthen      69315 Jul 22 1996 ps-print.el
  56. ;; He patched it for XEmacs.  
  57. ;; Steven L Baur <steve@miranova.com> sent me this version which has
  58. ;; 26 diffs with 19.34.
  59. ;; I merge these 26 diffs into my 3.04 version. 
  60.  
  61. ;; `ps-paper-type': ###autoload.
  62. ;; `ps-print-color-p' `ps-color-values': Replace pixel-components by
  63. ;;  color-instance-rgb-components for XEmacs.
  64. ;; `ps-color-device': New function to dynamically test the device
  65. ;;  color capability, added where ps-print-color-p is tested.
  66. ;; `ps-xemacs-face-kind-p': Fixed.
  67. ;; `ps-do-despool': Permit dynamic evaluation at print time of
  68. ;;  ps-lpr-switches.  
  69. ;; `ps-eval-switch' `ps-flatten-list' `ps-flatten-list-1': New for
  70. ;;  the previous feature.
  71. ;; `ps-gnus-print-article-from-summary': Updated for Gnus 5.
  72.  
  73.  
  74. ;; 3.04 [jack] after [simon] Oct 8, 1996 Simon Marshall <simon@gnu.ai.mit.edu>
  75. ;; `ps-print-version':
  76. ;;  Fix value.
  77. ;; `cl' `lisp-float-type':
  78. ;;  Require them.
  79. ;; `ps-number-of-columns' `ps-*-font-size':
  80. ;;  Try to select defaults better suited when `ps-landscape-mode' is non-nil. 
  81. ;; `ps-*-faces':
  82. ;;  Change default for Font Lock mode faces when `ps-print-color-p' is nil. 
  83. ;; `ps-right-header':
  84. ;;  Replace `time-stamp-yy/mm/dd' by `time-stamp-mon-dd-yyyy'. 
  85. ;; `ps-end-file' `ps-begin-page':
  86. ;;  Fix bug in page count for Ghostview. 
  87. ;; `ps-generate-postscript-with-faces':
  88. ;;  Replace `ps-sorter' by `car-less-than-car'.  
  89. ;; `ps-plot' `ps-generate':
  90. ;;  Replace `%d' by `%3d'.  
  91.  
  92. ;; 3.03 [jack] Sept 27, 1996 Jacques Duthen <duthen@cegelec-red.fr>
  93. ;; Merge 31 diffs between 19.29 and 19.34
  94.  
  95. ;; 3.02 [jack] June 26, 1996 Jacques Duthen <duthen@cegelec-red.fr>
  96. ;; Add new page dimensions to `ps-page-dimensions-database' for `paper-type'
  97. ;; Improve landscape mode `ps-landscape-mode' and multiple columns
  98. ;; printing `ps-number-of-columns':
  99. ;; The text and the margins are no more scaled.
  100. ;; Simplify the semantics of `ps-inter-column' (space between columns).
  101. ;; Add error checking for negative `ps-print-width' and `ps-print-height'.
  102. ;; Change the semantics of `ps-top-margin' which is now the TOP MARGIN,
  103. ;; and add `ps-header-offset' instead of having `ps-top-margin' split in 2.
  104. ;; Add `ps-header-font-family', `ps-header-font-size' and 
  105. ;; `ps-header-title-font-size' to control the header.
  106. ;; Add `ps-header-line-pad'.
  107. ;; Change the semantics of `ps-font-info-database' to have symbolic
  108. ;; font families.
  109. ;; Add new fonts to `ps-font-info-database': `Courier' `Helvetica'
  110. ;; `Times' `Palatino' `Helvetica-Narrow' `NewCenturySchlbk'
  111. ;; Make public `ps-font-family' and `ps-font-size' so that the user
  112. ;; can directly control the text font and size without loading ps-print.
  113. ;; Add error checking for unknown font families and a message giving
  114. ;; the exhaustive list of available font families.
  115. ;; Document how to install a new font family.
  116. ;; Add `/ReportAllFontInfo' to get all the font families of the printer.
  117. ;; Add the possibility to make `mixed' font families.
  118. ;; Add `ps-setup' to get the current setup.
  119. ;; Add tools `ps-line-lengths' `ps-nb-pages-buffer' `ps-nb-pages-region'
  120. ;; to help choose the font size.
  121. ;; Split `ps-print-prologue' in two to insert info from header fonts
  122. ;; Replace indexes by macro `ps-page-dimensions-get-width'
  123. ;; to get access to the dimensions list.
  124. ;; Add `ps-select-font' inside `ps-get-page-dimensions'.
  125. ;; Fix the "clumsy" `ps-page-height' management.
  126. ;; Move `ps-get-page-dimensions' to the beginning of `ps-begin-file'
  127. ;; to get early error checking.
  128. ;; Add sample setup `ps-jack-setup'.
  129. ;;
  130. ;; Rewrite a lot of postscript code and add comments inside it
  131. ;; (maybe they should not (or optionally) be included in the generated
  132. ;; Postscript).
  133. ;; Translate the origin to (lm, bm) to simplify the other moves.
  134. ;; Fix bug in `/HeaderOffset' with `/PrintStartY'.
  135. ;; Fix bug in `/SetHeaderLines'.
  136. ;; Change `/ReportFontInfo' for use by `/ReportAllFontInfo'.
  137.  
  138. ;; 3.01 [jack] June 4, 1996 Jacques Duthen <duthen@cegelec-red.fr>
  139. ;; Manage float value for every variable representing a size.
  140. ;; Add `ps-font-info-database' `ps-inter-column'
  141.  
  142. ;; 3.00 [jack] May 17, 1996 Jacques Duthen <duthen@cegelec-red.fr>
  143. ;;    based on 2.8 Jim's Pretty-Good version:
  144. ;; Add `ps-landscape-mode' and `ps-number-of-columns'
  145. ;; for dumb multi-column landscape mode.
  146.  
  147. ;; Baseline-version: 2.8.  (Jim's last change version -- this
  148. ;; file may have been edited as part of Emacs without changes to the
  149. ;; version number.  When reporting bugs, please also report the
  150. ;; version of Emacs, if any, that ps-print was distributed with.)
  151.  
  152. ;;; Commentary:
  153.  
  154. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  155. ;;
  156. ;; About ps-print
  157. ;; --------------
  158. ;;
  159. ;; This package provides printing of Emacs buffers on PostScript
  160. ;; printers; the buffer's bold and italic text attributes are
  161. ;; preserved in the printer output.  Ps-print is intended for use with
  162. ;; Emacs 19 or Lucid Emacs, together with a fontifying package such as
  163. ;; font-lock or hilit.
  164. ;;
  165. ;;
  166. ;; Using ps-print
  167. ;; --------------
  168. ;;
  169. ;; The Commands
  170. ;;
  171. ;; Ps-print provides eight commands for generating PostScript images
  172. ;; of Emacs buffers:
  173. ;;
  174. ;;        ps-print-buffer
  175. ;;        ps-print-buffer-with-faces
  176. ;;        ps-print-region
  177. ;;        ps-print-region-with-faces
  178. ;;        ps-spool-buffer
  179. ;;        ps-spool-buffer-with-faces
  180. ;;        ps-spool-region
  181. ;;        ps-spool-region-with-faces
  182. ;;
  183. ;; These commands all perform essentially the same function: they
  184. ;; generate PostScript images suitable for printing on a PostScript
  185. ;; printer or displaying with GhostScript.  These commands are
  186. ;; collectively referred to as "ps-print- commands".
  187. ;;
  188. ;; The word "print" or "spool" in the command name determines when the
  189. ;; PostScript image is sent to the printer:
  190. ;;
  191. ;;        print      - The PostScript image is immediately sent to the
  192. ;;                     printer;
  193. ;;
  194. ;;        spool      - The PostScript image is saved temporarily in an
  195. ;;                     Emacs buffer.  Many images may be spooled locally
  196. ;;                     before printing them.  To send the spooled images
  197. ;;                     to the printer, use the command `ps-despool'.
  198. ;;
  199. ;; The spooling mechanism was designed for printing lots of small
  200. ;; files (mail messages or netnews articles) to save paper that would
  201. ;; otherwise be wasted on banner pages, and to make it easier to find
  202. ;; your output at the printer (it's easier to pick up one 50-page
  203. ;; printout than to find 50 single-page printouts).
  204. ;; 
  205. ;; Ps-print has a hook in the `kill-emacs-hooks' so that you won't
  206. ;; accidentally quit from Emacs while you have unprinted PostScript
  207. ;; waiting in the spool buffer.  If you do attempt to exit with
  208. ;; spooled PostScript, you'll be asked if you want to print it, and if
  209. ;; you decline, you'll be asked to confirm the exit; this is modeled
  210. ;; on the confirmation that Emacs uses for modified buffers.
  211. ;;
  212. ;; The word "buffer" or "region" in the command name determines how
  213. ;; much of the buffer is printed:
  214. ;;
  215. ;;        buffer     - Print the entire buffer.
  216. ;;
  217. ;;        region     - Print just the current region.
  218. ;;
  219. ;; The -with-faces suffix on the command name means that the command
  220. ;; will include font, color, and underline information in the
  221. ;; PostScript image, so the printed image can look as pretty as the
  222. ;; buffer.  The ps-print- commands without the -with-faces suffix
  223. ;; don't include font, color, or underline information; images printed
  224. ;; with these commands aren't as pretty, but are faster to generate.
  225. ;;
  226. ;; Two ps-print- command examples:
  227. ;;
  228. ;;        ps-print-buffer             - print the entire buffer,
  229. ;;                                      without font, color, or
  230. ;;                                      underline information, and
  231. ;;                                      send it immediately to the
  232. ;;                                      printer.
  233. ;;
  234. ;;        ps-spool-region-with-faces  - print just the current region;
  235. ;;                                      include font, color, and
  236. ;;                                      underline information, and
  237. ;;                                      spool the image in Emacs to
  238. ;;                                      send to the printer later.
  239. ;;
  240. ;;
  241. ;; Invoking Ps-Print
  242. ;; -----------------
  243. ;;
  244. ;; To print your buffer, type
  245. ;;
  246. ;;        M-x ps-print-buffer
  247. ;;
  248. ;; or substitute one of the other seven ps-print- commands.  The
  249. ;; command will generate the PostScript image and print or spool it as
  250. ;; specified.  By giving the command a prefix argument
  251. ;;
  252. ;;        C-u M-x ps-print-buffer
  253. ;;
  254. ;; it will save the PostScript image to a file instead of sending it
  255. ;; to the printer; you will be prompted for the name of the file to
  256. ;; save the image to.  The prefix argument is ignored by the commands
  257. ;; that spool their images, but you may save the spooled images to a
  258. ;; file by giving a prefix argument to `ps-despool':
  259. ;;
  260. ;;        C-u M-x ps-despool
  261. ;;
  262. ;; When invoked this way, `ps-despool' will prompt you for the name of
  263. ;; the file to save to.
  264. ;;
  265. ;; Any of the `ps-print-' commands can be bound to keys; I recommend
  266. ;; binding `ps-spool-buffer-with-faces', `ps-spool-region-with-faces',
  267. ;; and `ps-despool'.  Here are the bindings I use on my Sun 4 keyboard:
  268. ;;
  269. ;;   (global-set-key 'f22 'ps-spool-buffer-with-faces) ;f22 is prsc
  270. ;;   (global-set-key '(shift f22) 'ps-spool-region-with-faces)
  271. ;;   (global-set-key '(control f22) 'ps-despool)
  272. ;;
  273. ;;
  274. ;; The Printer Interface
  275. ;; ---------------------
  276. ;;
  277. ;; The variables `ps-lpr-command' and `ps-lpr-switches' determine what
  278. ;; command is used to send the PostScript images to the printer, and
  279. ;; what arguments to give the command.  These are analogous to
  280. ;; `lpr-command' and `lpr-switches'.
  281. ;;
  282. ;; Make sure that they contain appropriate values for your system;
  283. ;; see the usage notes below and the documentation of these variables.
  284. ;;
  285. ;; NOTE: `ps-lpr-command' and `ps-lpr-switches' take their initial values
  286. ;;       from the variables `lpr-command' and `lpr-switches'.  If you have
  287. ;;       `lpr-command' set to invoke a pretty-printer such as `enscript',
  288. ;;       then ps-print won't work properly.  `ps-lpr-command' must name
  289. ;;       a program that does not format the files it prints.
  290. ;;
  291. ;;
  292. ;; The Page Layout
  293. ;; ---------------
  294. ;;
  295. ;; All dimensions are floats in PostScript points.
  296. ;; 1 inch  ==       2.54  cm    ==     72       points
  297. ;; 1 cm    ==  (/ 1 2.54) inch  ==  (/ 72 2.54) points
  298. ;;
  299. ;; The variable `ps-paper-type' determines the size of paper ps-print
  300. ;; formats for; it should contain one of the symbols:
  301. ;; `a4' `a3' `letter' `legal' `letter-small' `tabloid'
  302. ;; `ledger' `statement' `executive' `a4small' `b4' `b5'
  303. ;;
  304. ;; The variable `ps-landscape-mode' determines the orientation
  305. ;; of the printing on the page:
  306. ;; nil means `portrait' mode, non-nil means `landscape' mode.
  307. ;; There is no oblique mode yet, though this is easy to do in ps.
  308.  
  309. ;; In landscape mode, the text is NOT scaled: you may print 70 lines
  310. ;; in portrait mode and only 50 lignes in landscape mode.
  311. ;; The margins represent margins in the printed paper:
  312. ;; the top margin is the margin between the top of the page
  313. ;; and the printed header, whatever the orientation is.
  314. ;;
  315. ;; The variable `ps-number-of-columns' determines the number of columns
  316. ;; both in landscape and portrait mode.
  317. ;; You can use:
  318. ;; - (the standard) one column portrait mode
  319. ;; - (my favorite) two columns landscape mode (which spares trees)
  320. ;; but also
  321. ;; - one column landscape mode for files with very long lines.
  322. ;; - multi-column portrait or landscape mode
  323. ;;
  324. ;;
  325. ;; Horizontal layout
  326. ;; -----------------
  327. ;;
  328. ;; The horizontal layout is determined by the variables
  329. ;; `ps-left-margin' `ps-inter-column' `ps-right-margin'
  330. ;; as follows:
  331. ;;
  332. ;;  ------------------------------------------
  333. ;;  |    |      |    |      |    |      |    |
  334. ;;  | lm | text | ic | text | ic | text | rm |
  335. ;;  |    |      |    |      |    |      |    |
  336. ;;  ------------------------------------------
  337. ;;
  338. ;; If `ps-number-of-columns' is 1, `ps-inter-column' is not relevant.
  339. ;; Usually, lm = rm > 0 and ic = lm
  340. ;; If (ic < 0), the text of adjacent columns can overlap.
  341. ;;
  342. ;;
  343. ;; Vertical layout
  344. ;; ---------------
  345. ;;
  346. ;; The vertical layout is determined by the variables
  347. ;; `ps-bottom-margin' `ps-top-margin' `ps-header-offset'
  348. ;; as follows:
  349. ;;
  350. ;; |--------|        |--------|
  351. ;; | tm     |        | tm     |
  352. ;; |--------|        |--------|
  353. ;; | header |        |        |
  354. ;; |--------|        |        |
  355. ;; | ho     |        |        |
  356. ;; |--------|   or   | text   |
  357. ;; |        |        |        |
  358. ;; | text   |        |        |
  359. ;; |        |        |        |
  360. ;; |--------|        |--------|
  361. ;; | bm     |        | bm     |
  362. ;; |--------|        |--------|
  363. ;;
  364. ;; If `ps-print-header' is nil, `ps-header-offset' is not relevant.
  365. ;; The margins represent margins in the printed paper:
  366. ;; the top margin is the margin between the top of the page
  367. ;; and the printed header, whatever the orientation is.
  368. ;;
  369. ;;
  370. ;; Headers
  371. ;; -------
  372. ;;
  373. ;; Ps-print can print headers at the top of each column; the default
  374. ;; headers contain the following four items: on the left, the name of
  375. ;; the buffer and, if the buffer is visiting a file, the file's
  376. ;; directory; on the right, the page number and date of printing.
  377. ;; The default headers look something like this:
  378. ;;
  379. ;;     ps-print.el                                         1/21
  380. ;;     /home/jct/emacs-lisp/ps/new                     94/12/31
  381. ;; 
  382. ;; When printing on duplex printers, left and right are reversed so
  383. ;; that the page numbers are toward the outside (cf. `ps-spool-duplex').
  384. ;;
  385. ;; Headers are configurable:
  386. ;; To turn them off completely, set `ps-print-header' to nil.
  387. ;; To turn off the header's gaudy framing box,
  388. ;; set `ps-print-header-frame' to nil.
  389. ;;
  390. ;; The font family and size of text in the header are determined
  391. ;; by the variables `ps-header-font-family', `ps-header-font-size' and 
  392. ;; `ps-header-title-font-size' (see below).
  393. ;;
  394. ;; The variable `ps-header-line-pad' determines the portion of a header
  395. ;; title line height to insert between the header frame and the text
  396. ;; it contains, both in the vertical and horizontal directions:
  397. ;; .5 means half a line.
  398.  
  399. ;; Page numbers are printed in `n/m' format, indicating page n of m pages;
  400. ;; to omit the total page count and just print the page number,
  401. ;; set `ps-show-n-of-n' to nil.
  402. ;;
  403. ;; The amount of information in the header can be changed by changing
  404. ;; the number of lines.  To show less, set `ps-header-lines' to 1, and
  405. ;; the header will show only the buffer name and page number.  To show
  406. ;; more, set `ps-header-lines' to 3, and the header will show the time of
  407. ;; printing below the date.
  408. ;;
  409. ;; To change the content of the headers, change the variables
  410. ;; `ps-left-header' and `ps-right-header'.
  411. ;; These variables are lists, specifying top-to-bottom the text
  412. ;; to display on the left or right side of the header.
  413. ;; Each element of the list should be a string or a symbol.
  414. ;; Strings are inserted directly into the PostScript arrays,
  415. ;; and should contain the PostScript string delimiters '(' and ')'.
  416. ;;
  417. ;; Symbols in the header format lists can either represent functions
  418. ;; or variables.  Functions are called, and should return a string to
  419. ;; show in the header.  Variables should contain strings to display in
  420. ;; the header.  In either case, function or variable, the PostScript
  421. ;; string delimiters are added by ps-print, and should not be part of
  422. ;; the returned value.
  423. ;;
  424. ;; Here's an example: say we want the left header to display the text
  425. ;;
  426. ;;     Moe
  427. ;;     Larry
  428. ;;     Curly
  429. ;;
  430. ;; where we have a function to return "Moe"
  431. ;;
  432. ;;     (defun moe-func ()
  433. ;;       "Moe")
  434. ;;
  435. ;; a variable specifying "Larry"
  436. ;;
  437. ;;     (setq larry-var "Larry")
  438. ;;
  439. ;; and a literal for "Curly".  Here's how `ps-left-header' should be
  440. ;; set:
  441. ;;
  442. ;;     (setq ps-left-header (list 'moe-func 'larry-var "(Curly)"))
  443. ;;
  444. ;; Note that Curly has the PostScript string delimiters inside his
  445. ;; quotes -- those aren't misplaced lisp delimiters!
  446. ;;
  447. ;; Without them, PostScript would attempt to call the undefined
  448. ;; function Curly, which would result in a PostScript error.
  449. ;;
  450. ;; Since most printers don't report PostScript errors except by
  451. ;; aborting the print job, this kind of error can be hard to track down.
  452. ;;
  453. ;; Consider yourself warned!
  454. ;;
  455. ;;
  456. ;; Duplex Printers
  457. ;; ---------------
  458. ;;
  459. ;; If you have a duplex-capable printer (one that prints both sides of
  460. ;; the paper), set `ps-spool-duplex' to t.
  461. ;; Ps-print will insert blank pages to make sure each buffer starts
  462. ;; on the correct side of the paper.
  463. ;; Don't forget to set `ps-lpr-switches' to select duplex printing
  464. ;; for your printer.
  465. ;;
  466. ;; 
  467. ;; Font managing
  468. ;; -------------
  469. ;;
  470. ;; Ps-print now knows rather precisely some fonts:
  471. ;; the variable `ps-font-info-database' contains information
  472. ;; for a list of font families (currently mainly `Courier' `Helvetica'
  473. ;; `Times' `Palatino' `Helvetica-Narrow' `NewCenturySchlbk').
  474. ;; Each font family contains the font names for standard, bold, italic
  475. ;; and bold-italic characters, a reference size (usually 10) and the
  476. ;; corresponding line height, width of a space and average character width.
  477. ;; 
  478. ;; The variable `ps-font-family' determines which font family
  479. ;; is to be used for ordinary text.
  480. ;; If its value does not correspond to a known font family,
  481. ;; an error message is printed into the `*Messages*' buffer,
  482. ;; which lists the currently available font families.
  483. ;;
  484. ;; The variable `ps-font-size' determines the size (in points)
  485. ;; of the font for ordinary text, when generating Postscript.
  486. ;; Its value is a float.
  487. ;;
  488. ;; Similarly, the variable `ps-header-font-family' determines
  489. ;; which font family is to be used for text in the header.
  490. ;; The variable `ps-header-font-size' determines the font size,
  491. ;; in points, for text in the header.
  492. ;; The variable `ps-header-title-font-size' determines the font size,
  493. ;; in points, for the top line of text in the header.
  494. ;;
  495. ;;
  496. ;; Adding a new font family
  497. ;; ------------------------
  498. ;;
  499. ;; To use a new font family, you MUST first teach ps-print
  500. ;; this font, i.e., add its information to `ps-font-info-database',
  501. ;; otherwise ps-print cannot correctly place line and page breaks.
  502. ;;
  503. ;; For example, assuming `Helvetica' is unknown,
  504. ;; you first need to do the following ONLY ONCE:
  505. ;;
  506. ;; - create a new buffer
  507. ;; - generate the PostScript image to a file (C-u M-x ps-print-buffer)
  508. ;; - open this file and find the line:
  509. ;;    `% 3 cm 20 cm moveto  10 /Courier ReportFontInfo  showpage'
  510. ;; - delete the leading `%' (which is the Postscript comment character)
  511. ;; - replace in this line `Courier' by the new font (say `Helvetica')
  512. ;;   to get the line:
  513. ;;    `3 cm 20 cm moveto  10 /Helvetica ReportFontInfo  showpage'
  514. ;; - send this file to the printer (or to ghostscript).
  515. ;;   You should read the following on the output page:
  516. ;;
  517. ;;     For Helvetica 10 point, the line height is 11.56, the space width is 2.78
  518. ;;     and a crude estimate of average character width is 5.09243
  519. ;;
  520. ;; - Add these values to the `ps-font-info-database':
  521. ;;   (setq ps-font-info-database
  522. ;;     (append
  523. ;;      '((Helvetica ; the family name
  524. ;;        "Helvetica" "Helvetica-Bold" "Helvetica-Oblique" "Helvetica-BoldOblique"
  525. ;;        10.0 11.56 2.78 5.09243))
  526. ;;      ps-font-info-database))
  527. ;; - Now you can use this font family with any size:
  528. ;;    (setq ps-font-family 'Helvetica)
  529. ;; - if you want to use this family in another emacs session, you must
  530. ;;   put into your `~/.emacs':
  531. ;;    (require 'ps-print)
  532. ;;    (setq ps-font-info-database (append ...)))
  533. ;;   if you don't want to load ps-print, you have to copy the whole value:
  534. ;;    (setq ps-font-info-database '(<your stuff> <the standard stuff>))
  535. ;;   or, if you can wait until the `ps-print-hook' is implemented, do:
  536. ;;      (add-hook 'ps-print-hook '(setq ps-font-info-database (append ...)))
  537. ;;      This does not work yet, since there is no `ps-print-hook' yet.
  538. ;;
  539. ;; You can create new `mixed' font families like:
  540. ;;    (my-mixed-family
  541. ;;     "Courier-Bold" "Helvetica"
  542. ;;     "Zapf-Chancery-MediumItalic" "NewCenturySchlbk-BoldItalic"
  543. ;;     10.0 10.55 6.0 6.0)
  544. ;; Now you can use your new font family with any size:
  545. ;;    (setq ps-font-family 'my-mixed-family)
  546. ;;
  547. ;; You can get information on all the fonts resident in YOUR printer
  548. ;; by uncommenting the line:
  549. ;;    % 3 cm 20 cm moveto  ReportAllFontInfo           showpage
  550. ;;
  551. ;; The postscript file should be sent to YOUR postscript printer.
  552. ;; If you send it to ghostscript or to another postscript printer,
  553. ;; you may get slightly different results.
  554. ;; Anyway, as ghostscript fonts are autoload, you won't get
  555. ;; much font info.
  556. ;;
  557. ;;
  558. ;; How Ps-Print Deals With Faces
  559. ;; -----------------------------
  560. ;;
  561. ;; The ps-print-*-with-faces commands attempt to determine which faces
  562. ;; should be printed in bold or italic, but their guesses aren't
  563. ;; always right.  For example, you might want to map colors into faces
  564. ;; so that blue faces print in bold, and red faces in italic.
  565. ;;
  566. ;; It is possible to force ps-print to consider specific faces bold or
  567. ;; italic, no matter what font they are displayed in, by setting the
  568. ;; variables `ps-bold-faces' and `ps-italic-faces'.  These variables
  569. ;; contain lists of faces that ps-print should consider bold or
  570. ;; italic; to set them, put code like the following into your .emacs
  571. ;; file:
  572. ;;
  573. ;;     (setq ps-bold-faces '(my-blue-face))
  574. ;;      (setq ps-italic-faces '(my-red-face))
  575. ;;
  576. ;; Faces like bold-italic that are both bold and italic should go in
  577. ;; *both* lists.
  578. ;;
  579. ;; Ps-print keeps internal lists of which fonts are bold and which are
  580. ;; italic; these lists are built the first time you invoke ps-print.
  581. ;; For the sake of efficiency, the lists are built only once; the same
  582. ;; lists are referred in later invocations of ps-print.
  583. ;;
  584. ;; Because these lists are built only once, it's possible for them to
  585. ;; get out of sync, if a face changes, or if new faces are added.  To
  586. ;; get the lists back in sync, you can set the variable
  587. ;; `ps-build-face-reference' to t, and the lists will be rebuilt the
  588. ;; next time ps-print is invoked.
  589. ;;
  590. ;;
  591. ;; How Ps-Print Deals With Color
  592. ;; -----------------------------
  593. ;;
  594. ;; Ps-print detects faces with foreground and background colors
  595. ;; defined and embeds color information in the PostScript image.
  596. ;; The default foreground and background colors are defined by the
  597. ;; variables `ps-default-fg' and `ps-default-bg'.
  598. ;; On black-and-white printers, colors are displayed in grayscale.
  599. ;; To turn off color output, set `ps-print-color-p' to nil.
  600. ;;
  601. ;;
  602. ;; Utilities
  603. ;; ---------
  604. ;;
  605. ;; Some tools are provided to help you customize your font setup.
  606. ;;
  607. ;; `ps-setup' returns (some part of) the current setup.
  608. ;;
  609. ;; To avoid wrapping too many lines, you may want to adjust the
  610. ;; left and right margins and the font size.  On UN*X systems, do:
  611. ;; pr -t file | awk '{printf "%3d %s\n", length($0), $0}' | sort -r | head
  612. ;; to determine the longest lines of your file.
  613. ;; Then, the command `ps-line-lengths' will give you the correspondence
  614. ;; between a line length (number of characters) and the maximum font
  615. ;; size which doesn't wrap such a line with the current ps-print setup.
  616. ;;
  617. ;; The commands `ps-nb-pages-buffer' and `ps-nb-pages-region' display
  618. ;; the correspondence between a number of pages and the maximum font
  619. ;; size which allow the number of lines of the current buffer or of
  620. ;; its current region to fit in this number of pages.
  621. ;; Note: line folding is not taken into account in this process
  622. ;; and could change the results.
  623. ;;
  624. ;;
  625. ;; New since version 1.5
  626. ;; ---------------------
  627. ;;
  628. ;; Color output capability.
  629. ;; Automatic detection of font attributes (bold, italic).
  630. ;; Configurable headers with page numbers.
  631. ;; Slightly faster.
  632. ;; Support for different paper sizes.
  633. ;; Better conformance to PostScript Document Structure Conventions.
  634. ;;
  635. ;;
  636. ;; New since version 2.8
  637. ;; ---------------------
  638. ;;
  639. ;; [jack] 960517 Jacques Duthen <duthen@cegelec-red.fr>
  640. ;;
  641. ;; Font familiy and float size for text and header.
  642. ;; Landscape mode.
  643. ;; Multiple columns.
  644. ;; Tools for page setup.
  645. ;;
  646. ;;
  647. ;; Known bugs and limitations of ps-print:
  648. ;; --------------------------------------
  649. ;;
  650. ;; Although color printing will work in XEmacs 19.12, it doesn't work
  651. ;; well; in particular, bold or italic fonts don't print in the right
  652. ;; background color.
  653. ;;
  654. ;; Invisible properties aren't correctly ignored in XEmacs 19.12.
  655. ;;
  656. ;; Automatic font-attribute detection doesn't work well, especially
  657. ;; with hilit19 and older versions of get-create-face.  Users having
  658. ;; problems with auto-font detection should use the lists
  659. ;; `ps-italic-faces' and `ps-bold-faces' and/or turn off automatic
  660. ;; detection by setting `ps-auto-font-detect' to nil.
  661. ;;
  662. ;; Automatic font-attribute detection doesn't work with XEmacs 19.12
  663. ;; in tty mode; use the lists `ps-italic-faces' and `ps-bold-faces'
  664. ;; instead.
  665. ;;
  666. ;; Still too slow; could use some hand-optimization.
  667. ;;
  668. ;; ASCII Control characters other than tab, linefeed and pagefeed are
  669. ;; not handled.
  670. ;;
  671. ;; Default background color isn't working.
  672. ;;
  673. ;; Faces are always treated as opaque.
  674. ;;
  675. ;; Epoch and Emacs 18 not supported.  At all.
  676. ;;
  677. ;; Fixed-pitch fonts work better for line folding, but are not required.  
  678. ;;
  679. ;; `ps-nb-pages-buffer' and `ps-nb-pages-region' don't take care
  680. ;; of folding lines.
  681. ;;
  682. ;;
  683. ;; Things to change:
  684. ;; ----------------
  685. ;;
  686. ;; Add `ps-print-hook' (I don't know how to do that (yet!)).
  687. ;; Add 4-up capability (really needed?).
  688. ;; Add line numbers (should not be too hard).
  689. ;; Add `ps-non-bold-faces' and `ps-non-italic-faces' (should be easy).
  690. ;; Put one header per page over the columns (easy but needed?).
  691. ;; Improve the memory management for big files (hard?).
  692. ;; `ps-nb-pages-buffer' and `ps-nb-pages-region' should take care
  693. ;; of folding lines.
  694. ;;
  695. ;;
  696. ;; Acknowledgements
  697. ;; ----------------
  698. ;; Thanks to Jim Thompson <?@?> for the 2.8 version I started from.
  699. ;; [jack]
  700. ;;
  701. ;; Thanks to Kevin Rodgers <kevinr@ihs.com> for adding support for
  702. ;; color and the invisible property.
  703. ;;
  704. ;; Thanks to Avishai Yacobi, avishaiy@mcil.comm.mot.com, for writing
  705. ;; the initial port to Emacs 19.  His code is no longer part of
  706. ;; ps-print, but his work is still appreciated.
  707. ;;
  708. ;; Thanks to Remi Houdaille and Michel Train, michel@metasoft.fdn.org,
  709. ;; for adding underline support.  Their code also is no longer part of
  710. ;; ps-print, but their efforts are not forgotten.
  711. ;;
  712. ;; Thanks also to all of you who mailed code to add features to
  713. ;; ps-print; although I didn't use your code, I still appreciate your
  714. ;; sharing it with me.
  715. ;;
  716. ;; Thanks to all who mailed comments, encouragement, and criticism.
  717. ;; Thanks also to all who responded to my survey; I had too many
  718. ;; responses to reply to them all, but I greatly appreciate your
  719. ;; interest.
  720. ;;
  721. ;; Jim
  722. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  723.  
  724. ;;; Code:
  725.  
  726. (eval-when-compile
  727.   (require 'cl))
  728.  
  729. (unless (featurep 'lisp-float-type)
  730.   (error "`ps-print' requires floating point support"))
  731.  
  732. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  733. ;; User Variables:
  734.  
  735. ;;; Interface to the command system
  736.  
  737. (defgroup ps-print nil
  738.   "Postscript generator for Emacs 19"
  739.   :prefix "ps-"
  740.   :group 'wp)
  741.  
  742. (defgroup ps-print-horizontal nil
  743.   "Horizontal page layout"
  744.   :prefix "ps-"
  745.   :tag "Horizontal"
  746.   :group 'ps-print)
  747.  
  748. (defgroup ps-print-vertical nil
  749.   "Vertical page layout"
  750.   :prefix "ps-"
  751.   :tag "Vertical"
  752.   :group 'ps-print)
  753.  
  754. (defgroup ps-print-header nil
  755.   "Headers layout"
  756.   :prefix "ps-"
  757.   :tag "Header"
  758.   :group 'ps-print)
  759.  
  760. (defgroup ps-print-font nil
  761.   "Fonts customization"
  762.   :prefix "ps-"
  763.   :tag "Font"
  764.   :group 'ps-print)
  765.  
  766. (defgroup ps-print-color nil
  767.   "Color customization"
  768.   :prefix "ps-"
  769.   :tag "Color"
  770.   :group 'ps-print)
  771.  
  772. (defgroup ps-print-face nil
  773.   "Faces customization"
  774.   :prefix "ps-"
  775.   :tag "PS Faces"
  776.   :group 'ps-print
  777.   :group 'faces)
  778.  
  779.  
  780. (defcustom ps-lpr-command lpr-command
  781.   "*The shell command for printing a PostScript file."
  782.   :type 'string
  783.   :group 'ps-print)
  784.  
  785. (defcustom ps-lpr-switches lpr-switches
  786.   "*A list of extra switches to pass to `ps-lpr-command'."
  787.   :type '(repeat string)
  788.   :group 'ps-print)
  789.  
  790. ;;; Page layout
  791.  
  792. ;; All page dimensions are in PostScript points.
  793. ;; 1 inch  ==       2.54  cm    ==     72       points
  794. ;; 1 cm    ==  (/ 1 2.54) inch  ==  (/ 72 2.54) points
  795.  
  796. ;; Letter      8.5   inch x 11.0   inch
  797. ;; Legal       8.5   inch x 14.0   inch
  798. ;; A4          8.26  inch x 11.69  inch = 21.0 cm x 29.7 cm
  799.  
  800. ;; LetterSmall 7.68  inch x 10.16  inch
  801. ;; Tabloid    11.0   inch x 17.0   inch
  802. ;; Ledger     17.0   inch x 11.0   inch
  803. ;; Statement   5.5   inch x  8.5   inch
  804. ;; Executive   7.5   inch x 10.0   inch
  805. ;; A3         11.69  inch x 16.5   inch = 29.7 cm x 42.0 cm
  806. ;; A4Small     7.47  inch x 10.85  inch
  807. ;; B4         10.125 inch x 14.33  inch
  808. ;; B5          7.16  inch x 10.125 inch
  809.  
  810. (defcustom ps-page-dimensions-database
  811.   (list (list 'a4    (/ (* 72 21.0) 2.54) (/ (* 72 29.7) 2.54))
  812.     (list 'a3    (/ (* 72 29.7) 2.54) (/ (* 72 42.0) 2.54))
  813.     (list 'letter       (* 72  8.5)   (* 72 11.0))
  814.     (list 'legal        (* 72  8.5)   (* 72 14.0))
  815.     (list 'letter-small (* 72  7.68)  (* 72 10.16))
  816.     (list 'tabloid      (* 72 11.0)   (* 72 17.0))
  817.     (list 'ledger       (* 72 17.0)   (* 72 11.0))
  818.     (list 'statement    (* 72  5.5)   (* 72  8.5))
  819.     (list 'executive    (* 72  7.5)   (* 72 10.0))
  820.     (list 'a4small      (* 72  7.47)  (* 72 10.85))
  821.     (list 'b4           (* 72 10.125) (* 72 14.33))
  822.     (list 'b5           (* 72  7.16)  (* 72 10.125)))
  823.   "*List associating a symbolic paper type to its width and height.
  824. see `ps-paper-type'."
  825.   :type '(repeat (list :tag "Paper Type"
  826.                (symbol :tag "Name")
  827.                (number :tag "Width")
  828.                (number :tag "Height")))
  829.   :group 'ps-print)
  830.  
  831. ;;;###autoload
  832. (defcustom ps-paper-type 'letter
  833.   "*Specifies the size of paper to format for.
  834. Should be one of the paper types defined in `ps-page-dimensions-database', for
  835. example `letter', `legal' or `a4'."
  836.   :type '(symbol :validate (lambda (wid)
  837.                  (if (assq (widget-value wid) ps-page-dimensions-database)
  838.                  nil
  839.                    (widget-put wid :error "Unknown paper size")
  840.                    wid)))
  841.   :group 'ps-print)
  842.  
  843. (defcustom ps-landscape-mode 'nil
  844.   "*Non-nil means print in landscape mode."
  845.   :type 'boolean
  846.   :group 'ps-print)
  847.  
  848. (defcustom ps-number-of-columns (if ps-landscape-mode 2 1)
  849.   "*Specifies the number of columns"
  850.   :type 'integer
  851.   :group 'ps-print)
  852.  
  853. ;;; Horizontal layout
  854.  
  855. ;;  ------------------------------------------
  856. ;;  |    |      |    |      |    |      |    |
  857. ;;  | lm | text | ic | text | ic | text | rm |
  858. ;;  |    |      |    |      |    |      |    |
  859. ;;  ------------------------------------------
  860.  
  861. (defcustom ps-left-margin   (/ (* 72  2.0) 2.54) ;   2 cm
  862.   "*Left margin in points (1/72 inch)."
  863.   :type 'number
  864.   :group 'ps-print-horizontal)
  865.  
  866. (defcustom ps-right-margin  (/ (* 72  2.0) 2.54) ;   2 cm
  867.   "*Right margin in points (1/72 inch)."
  868.   :type 'number
  869.   :group 'ps-print-horizontal)
  870.  
  871. (defcustom ps-inter-column  (/ (* 72  2.0) 2.54) ;   2 cm
  872.   "*Horizontal space between columns in points (1/72 inch)."
  873.   :type 'number
  874.   :group 'ps-print-horizontal)
  875.  
  876. ;;; Vertical layout
  877.  
  878. ;; |--------|
  879. ;; | tm     |
  880. ;; |--------|
  881. ;; | header |
  882. ;; |--------|
  883. ;; | ho     |
  884. ;; |--------|
  885. ;; | text   |
  886. ;; |--------|
  887. ;; | bm     |
  888. ;; |--------|
  889.  
  890. (defcustom ps-bottom-margin (/ (* 72  1.5) 2.54) ; 1.5 cm
  891.   "*Bottom margin in points (1/72 inch)."
  892.   :type 'number
  893.   :group 'ps-print-vertical)
  894.  
  895. (defcustom ps-top-margin    (/ (* 72  1.5) 2.54) ; 1.5 cm
  896.   "*Top margin in points (1/72 inch)."
  897.   :type 'number
  898.   :group 'ps-print-vertical)
  899.  
  900. (defcustom ps-header-offset (/ (* 72  1.0) 2.54) ; 1.0 cm
  901.   "*Vertical space in points (1/72 inch) between the main text and the header."
  902.   :type 'number
  903.   :group 'ps-print-vertical)
  904.  
  905. (defcustom ps-header-line-pad 0.15
  906.   "*Portion of a header title line height to insert between the header frame
  907. and the text it contains, both in the vertical and horizontal directions."
  908.   :type 'number
  909.   :group 'ps-print-vertical)
  910.  
  911. ;;; Header setup
  912.  
  913. (defcustom ps-print-header t
  914.   "*Non-nil means print a header at the top of each page.
  915. By default, the header displays the buffer name, page number, and, if
  916. the buffer is visiting a file, the file's directory.  Headers are
  917. customizable by changing variables `ps-header-left' and
  918. `ps-header-right'."
  919.   :type 'boolean
  920.   :group 'ps-print-header)
  921.  
  922. (defcustom ps-print-header-frame t
  923.   "*Non-nil means draw a gaudy frame around the header."
  924.   :type 'boolean
  925.   :group 'ps-print-header)
  926.  
  927. (defcustom ps-header-lines 2
  928.   "*Number of lines to display in page header, when generating Postscript."
  929.   :type 'integer
  930.   :group 'ps-print-header)
  931. (make-variable-buffer-local 'ps-header-lines)
  932.  
  933. (defcustom ps-show-n-of-n t
  934.   "*Non-nil means show page numbers as N/M, meaning page N of M.
  935. Note: page numbers are displayed as part of headers, see variable
  936. `ps-print-headers'."
  937.   :type 'boolean
  938.   :group 'ps-print-header)
  939.  
  940. (defcustom ps-spool-duplex nil        ; Not many people have duplex
  941.                     ; printers, so default to nil.
  942.   "*Non-nil indicates spooling is for a two-sided printer.
  943. For a duplex printer, the `ps-spool-*' commands will insert blank pages
  944. as needed between print jobs so that the next buffer printed will
  945. start on the right page.  Also, if headers are turned on, the headers
  946. will be reversed on duplex printers so that the page numbers fall to
  947. the left on even-numbered pages."
  948.   :type 'boolean
  949.   :group 'ps-print-header)
  950.  
  951. ;;; Fonts
  952.  
  953. (defcustom ps-font-info-database
  954.   '((Courier                ; the family key
  955.      "Courier" "Courier-Bold" "Courier-Oblique" "Courier-BoldOblique"
  956.      10.0 10.55 6.0     6.0)
  957.     (Helvetica                ; the family key
  958.      "Helvetica" "Helvetica-Bold" "Helvetica-Oblique" "Helvetica-BoldOblique"
  959.      10.0 11.56 2.78    5.09243)
  960.     (Times
  961.      "Times-Roman" "Times-Bold" "Times-Italic" "Times-BoldItalic"
  962.      10.0 11.0  2.5     4.71432)
  963.     (Palatino
  964.      "Palatino-Roman" "Palatino-Bold" "Palatino-Italic" "Palatino-BoldItalic"
  965.      10.0 12.1  2.5     5.08676)
  966.     (Helvetica-Narrow
  967.      "Helvetica-Narrow" "Helvetica-Narrow-Bold"
  968.      "Helvetica-Narrow-Oblique" "Helvetica-Narrow-BoldOblique"
  969.      10.0 11.56 2.2796  4.17579)
  970.     (NewCenturySchlbk
  971.      "NewCenturySchlbk-Roman" "NewCenturySchlbk-Bold"
  972.      "NewCenturySchlbk-Italic" "NewCenturySchlbk-BoldItalic"
  973.      10.0 12.15 2.78    5.31162)
  974.     ;; got no bold for the next ones
  975.     (AvantGarde-Book
  976.      "AvantGarde-Book" "AvantGarde-Book"
  977.      "AvantGarde-BookOblique" "AvantGarde-BookOblique"
  978.      10.0 11.77 2.77    5.45189)
  979.     (AvantGarde-Demi
  980.      "AvantGarde-Demi" "AvantGarde-Demi"
  981.      "AvantGarde-DemiOblique" "AvantGarde-DemiOblique"
  982.      10.0 12.72 2.8     5.51351)
  983.     (Bookman-Demi
  984.      "Bookman-Demi" "Bookman-Demi"
  985.      "Bookman-DemiItalic" "Bookman-DemiItalic"
  986.      10.0 11.77 3.4     6.05946)
  987.     (Bookman-Light
  988.      "Bookman-Light" "Bookman-Light"
  989.      "Bookman-LightItalic" "Bookman-LightItalic"
  990.      10.0 11.79 3.2     5.67027)
  991.     ;; got no bold and no italic for the next ones
  992.     (Symbol
  993.      "Symbol" "Symbol" "Symbol" "Symbol"
  994.      10.0 13.03 2.5     3.24324)
  995.     (Zapf-Dingbats
  996.      "Zapf-Dingbats" "Zapf-Dingbats" "Zapf-Dingbats" "Zapf-Dingbats"
  997.      10.0  9.63 2.78    2.78)
  998.     (Zapf-Chancery-MediumItalic
  999.      "Zapf-Chancery-MediumItalic" "Zapf-Chancery-MediumItalic"
  1000.      "Zapf-Chancery-MediumItalic" "Zapf-Chancery-MediumItalic"
  1001.      10.0 11.45 2.2     4.10811)
  1002. )
  1003.   "*Font info database: font family (the key), name, bold, italic, bold-italic,
  1004. reference size, line height, space width, average character width.
  1005. To get the info for another specific font (say Helvetica), do the following:
  1006. - create a new buffer
  1007. - generate the PostScript image to a file (C-u M-x ps-print-buffer)
  1008. - open this file and delete the leading `%' (which is the Postscript
  1009.   comment character) from the line
  1010.     `% 3 cm 20 cm moveto  10 /Courier ReportFontInfo  showpage'
  1011.   to get the line
  1012.     `3 cm 20 cm moveto  10 /Helvetica ReportFontInfo  showpage'
  1013. - add the values to `ps-font-info-database'.
  1014. You can get all the fonts of YOUR printer using `ReportAllFontInfo'."
  1015.   :type '(repeat (list :tag "Font Definition"
  1016.                (symbol :tag "Font")
  1017.                (string :tag "Name")
  1018.                (string :tag "Bold")
  1019.                (string :tag "Italic")
  1020.                (string :tag "Bold-Italic")
  1021.                (number :tag "Reference Size")
  1022.                (number :tag "Line Height")
  1023.                (number :tag "Space Width")
  1024.                (number :tag "Average Character Width")))
  1025.   :group 'ps-print-font)
  1026.  
  1027. (defcustom ps-font-family 'Courier
  1028.   "Font family name for ordinary text, when generating Postscript."
  1029.   :type 'symbol
  1030.   :group 'ps-print-font)
  1031.  
  1032. (defcustom ps-font-size   (if ps-landscape-mode 7 8.5)
  1033.   "Font size, in points, for ordinary text, when generating Postscript."
  1034.   :type 'number
  1035.   :group 'ps-print-font)
  1036.  
  1037. (defcustom ps-header-font-family      'Helvetica
  1038.   "Font family name for text in the header, when generating Postscript."
  1039.   :type 'symbol
  1040.   :group 'ps-print-font)
  1041.  
  1042. (defcustom ps-header-font-size       (if ps-landscape-mode 10 12)
  1043.   "Font size, in points, for text in the header, when generating Postscript."
  1044.   :type 'number
  1045.   :group 'ps-print-font)
  1046.  
  1047. (defcustom ps-header-title-font-size (if ps-landscape-mode 12 14)
  1048.   "Font size, in points, for the top line of text in the header,
  1049. when generating Postscript."
  1050.   :type 'number
  1051.   :group 'ps-print-font)
  1052.  
  1053. ;;; Colors
  1054.  
  1055. ;;;###autoload
  1056. ;;; The 19.33 fsf version includes a test on pixel components instead
  1057. ;;;  of color-instance-rgb-components
  1058. (defcustom ps-print-color-p (or (fboundp 'x-color-values)    ; fsf
  1059.                  (fboundp 'color-instance-rgb-components))
  1060.                     ; xemacs
  1061. ; Printing color requires x-color-values.
  1062.   "*If non-nil, print the buffer's text in color."
  1063.   :type 'boolean
  1064.   :group 'ps-print-color)
  1065.  
  1066. (defcustom ps-default-fg '(0.0 0.0 0.0)
  1067.   "*RGB values of the default foreground color.  Defaults to black."
  1068.   :type '(list (number :tag "Red") (number :tag "Green") (number :tag "Blue"))
  1069.   :group 'ps-print-color)
  1070.  
  1071. (defcustom ps-default-bg '(1.0 1.0 1.0)
  1072.   "*RGB values of the default background color.  Defaults to white."
  1073.   :type '(list (number :tag "Red") (number :tag "Green") (number :tag "Blue"))
  1074.   :group 'ps-print-color)
  1075.  
  1076. (defcustom ps-auto-font-detect t
  1077.   "*Non-nil means automatically detect bold/italic face attributes.
  1078. nil means rely solely on the lists `ps-bold-faces', `ps-italic-faces',
  1079. and `ps-underlined-faces'."
  1080.   :type 'boolean
  1081.   :group 'ps-print-font)
  1082.  
  1083. (defcustom ps-bold-faces
  1084.   (unless ps-print-color-p
  1085.     '(font-lock-function-name-face
  1086.       font-lock-builtin-face
  1087.       font-lock-variable-name-face
  1088.       font-lock-keyword-face
  1089.       font-lock-warning-face))
  1090.   "*A list of the \(non-bold\) faces that should be printed in bold font.
  1091. This applies to generating Postscript."
  1092.   :type '(repeat face)
  1093.   :group 'ps-print-face)
  1094.  
  1095. (defcustom ps-italic-faces
  1096.   (unless ps-print-color-p
  1097.     '(font-lock-variable-name-face
  1098.       font-lock-string-face
  1099.       font-lock-comment-face
  1100.       font-lock-warning-face))
  1101.   "*A list of the \(non-italic\) faces that should be printed in italic font.
  1102. This applies to generating Postscript."
  1103.   :type '(repeat face)
  1104.   :group 'ps-print-face)
  1105.  
  1106. (defcustom ps-underlined-faces
  1107.   (unless ps-print-color-p
  1108.     '(font-lock-function-name-face
  1109.       font-lock-type-face
  1110.       font-lock-reference-face
  1111.       font-lock-warning-face))
  1112.   "*A list of the \(non-underlined\) faces that should be printed underlined.
  1113. This applies to generating Postscript."
  1114.   :type '(repeat face)
  1115.   :group 'ps-print-face)
  1116.  
  1117. (defcustom ps-left-header
  1118.   (list 'ps-get-buffer-name 'ps-header-dirpart)
  1119.   "*The items to display (each on a line) on the left part of the page header.
  1120. This applies to generating Postscript.
  1121.  
  1122. The value should be a list of strings and symbols, each representing an
  1123. entry in the PostScript array HeaderLinesLeft.
  1124.  
  1125. Strings are inserted unchanged into the array; those representing
  1126. PostScript string literals should be delimited with PostScript string
  1127. delimiters '(' and ')'.
  1128.  
  1129. For symbols with bound functions, the function is called and should
  1130. return a string to be inserted into the array.  For symbols with bound
  1131. values, the value should be a string to be inserted into the array.
  1132. In either case, function or variable, the string value has PostScript
  1133. string delimiters added to it."
  1134.   :type '(repeat (choice string symbol))
  1135.   :group 'ps-print-header)
  1136. (make-variable-buffer-local 'ps-left-header)
  1137.  
  1138. (defcustom ps-right-header
  1139.   (list "/pagenumberstring load" 'time-stamp-mon-dd-yyyy 'time-stamp-hh:mm:ss)
  1140.   "*The items to display (each on a line) on the right part of the page header.
  1141. This applies to generating Postscript.
  1142.  
  1143. See the variable `ps-left-header' for a description of the format of
  1144. this variable."
  1145.   :type '(repeat (choice string symbol))
  1146.   :group 'ps-print-header)
  1147. (make-variable-buffer-local 'ps-right-header)
  1148.  
  1149. (defcustom ps-razzle-dazzle t
  1150.   "*Non-nil means report progress while formatting buffer."
  1151.   :type 'boolean
  1152.   :group 'ps-print)
  1153.  
  1154. (defvar ps-adobe-tag "%!PS-Adobe-3.0\n"
  1155.   "*Contains the header line identifying the output as PostScript.
  1156. By default, `ps-adobe-tag' contains the standard identifier.  Some
  1157. printers require slightly different versions of this line.")
  1158.  
  1159. (defcustom ps-build-face-reference t
  1160.   "*Non-nil means build the reference face lists.
  1161.  
  1162. Ps-print sets this value to nil after it builds its internal reference
  1163. lists of bold and italic faces.  By settings its value back to t, you
  1164. can force ps-print to rebuild the lists the next time you invoke one
  1165. of the ...-with-faces commands.
  1166.  
  1167. You should set this value back to t after you change the attributes of
  1168. any face, or create new faces.  Most users shouldn't have to worry
  1169. about its setting, though."
  1170.   :type 'boolean
  1171.   :group 'ps-print-face)
  1172.  
  1173. (defcustom ps-always-build-face-reference nil
  1174.   "*Non-nil means always rebuild the reference face lists.
  1175.  
  1176. If this variable is non-nil, ps-print will rebuild its internal
  1177. reference lists of bold and italic faces *every* time one of the
  1178. -with-faces commands is called.  Most users shouldn't need to set this
  1179. variable."
  1180.   :type 'boolean
  1181.   :group 'ps-print-face)
  1182.  
  1183. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1184. ;; User commands
  1185.  
  1186. ;;;###autoload
  1187. (defun ps-print-buffer (&optional filename)
  1188.   "Generate and print a PostScript image of the buffer.
  1189.  
  1190. When called with a numeric prefix argument (C-u), prompts the user for
  1191. the name of a file to save the PostScript image in, instead of sending
  1192. it to the printer.
  1193.  
  1194. More specifically, the FILENAME argument is treated as follows: if it
  1195. is nil, send the image to the printer.  If FILENAME is a string, save
  1196. the PostScript image in a file with that name.  If FILENAME is a
  1197. number, prompt the user for the name of the file to save in."
  1198.  
  1199.   (interactive (list (ps-print-preprint current-prefix-arg)))
  1200.   (ps-generate (current-buffer) (point-min) (point-max)
  1201.            'ps-generate-postscript)
  1202.   (ps-do-despool filename))
  1203.  
  1204.  
  1205. ;;;###autoload
  1206. (defun ps-print-buffer-with-faces (&optional filename)
  1207.   "Generate and print a PostScript image of the buffer.
  1208. Like `ps-print-buffer', but includes font, color, and underline
  1209. information in the generated image.  This command works only if you
  1210. are using a window system, so it has a way to determine color values."
  1211.   (interactive (list (ps-print-preprint current-prefix-arg)))
  1212.   (ps-generate (current-buffer) (point-min) (point-max)
  1213.            'ps-generate-postscript-with-faces)
  1214.   (ps-do-despool filename))
  1215.  
  1216.  
  1217. ;;;###autoload
  1218. (defun ps-print-region (from to &optional filename)
  1219.   "Generate and print a PostScript image of the region.
  1220. Like `ps-print-buffer', but prints just the current region."
  1221.  
  1222.   (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg)))
  1223.   (ps-generate (current-buffer) from to
  1224.            'ps-generate-postscript)
  1225.   (ps-do-despool filename))
  1226.  
  1227.  
  1228. ;;;###autoload
  1229. (defun ps-print-region-with-faces (from to &optional filename)
  1230.   "Generate and print a PostScript image of the region.
  1231. Like `ps-print-region', but includes font, color, and underline
  1232. information in the generated image.  This command works only if you
  1233. are using a window system, so it has a way to determine color values."
  1234.  
  1235.   (interactive (list (point) (mark) (ps-print-preprint current-prefix-arg)))
  1236.   (ps-generate (current-buffer) from to
  1237.            'ps-generate-postscript-with-faces)
  1238.   (ps-do-despool filename))
  1239.  
  1240.  
  1241. ;;;###autoload
  1242. (defun ps-spool-buffer ()
  1243.   "Generate and spool a PostScript image of the buffer.
  1244. Like `ps-print-buffer' except that the PostScript image is saved in a
  1245. local buffer to be sent to the printer later.
  1246.  
  1247. Use the command `ps-despool' to send the spooled images to the printer."
  1248.   (interactive)
  1249.   (ps-generate (current-buffer) (point-min) (point-max)
  1250.            'ps-generate-postscript))
  1251.  
  1252.  
  1253. ;;;###autoload
  1254. (defun ps-spool-buffer-with-faces ()
  1255.   "Generate and spool a PostScript image of the buffer.
  1256. Like `ps-spool-buffer', but includes font, color, and underline
  1257. information in the generated image.  This command works only if you
  1258. are using a window system, so it has a way to determine color values.
  1259.  
  1260. Use the command `ps-despool' to send the spooled images to the printer."
  1261.  
  1262.   (interactive)
  1263.   (ps-generate (current-buffer) (point-min) (point-max)
  1264.            'ps-generate-postscript-with-faces))
  1265.  
  1266.  
  1267. ;;;###autoload
  1268. (defun ps-spool-region (from to)
  1269.   "Generate a PostScript image of the region and spool locally.
  1270. Like `ps-spool-buffer', but spools just the current region.
  1271.  
  1272. Use the command `ps-despool' to send the spooled images to the printer."
  1273.   (interactive "r")
  1274.   (ps-generate (current-buffer) from to
  1275.            'ps-generate-postscript))
  1276.  
  1277.  
  1278. ;;;###autoload
  1279. (defun ps-spool-region-with-faces (from to)
  1280.   "Generate a PostScript image of the region and spool locally.
  1281. Like `ps-spool-region', but includes font, color, and underline
  1282. information in the generated image.  This command works only if you
  1283. are using a window system, so it has a way to determine color values.
  1284.  
  1285. Use the command `ps-despool' to send the spooled images to the printer."
  1286.   (interactive "r")
  1287.   (ps-generate (current-buffer) from to
  1288.            'ps-generate-postscript-with-faces))
  1289.  
  1290. ;;;###autoload
  1291. (defun ps-despool (&optional filename)
  1292.   "Send the spooled PostScript to the printer.
  1293.  
  1294. When called with a numeric prefix argument (C-u), prompt the user for
  1295. the name of a file to save the spooled PostScript in, instead of sending
  1296. it to the printer.
  1297.  
  1298. More specifically, the FILENAME argument is treated as follows: if it
  1299. is nil, send the image to the printer.  If FILENAME is a string, save
  1300. the PostScript image in a file with that name.  If FILENAME is a
  1301. number, prompt the user for the name of the file to save in."
  1302.   (interactive (list (ps-print-preprint current-prefix-arg)))
  1303.   (ps-do-despool filename))
  1304.  
  1305. ;;;###autoload
  1306. (defun ps-line-lengths ()
  1307.   "*Display the correspondence between a line length and a font size,
  1308. using the current ps-print setup.
  1309. Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
  1310.   (interactive)
  1311.   (ps-line-lengths-internal))
  1312.  
  1313. ;;;###autoload
  1314. (defun ps-nb-pages-buffer (nb-lines)
  1315.   "*Display an approximate correspondence between a font size and the number
  1316. of pages the current buffer would require to print
  1317. using the current ps-print setup."
  1318.   (interactive (list (count-lines (point-min) (point-max))))
  1319.   (ps-nb-pages nb-lines))
  1320.  
  1321. ;;;###autoload
  1322. (defun ps-nb-pages-region (nb-lines)
  1323.   "*Display an approximate correspondence between a font size and the number
  1324. of pages the current region would require to print
  1325. using the current ps-print setup."
  1326.   (interactive (list (count-lines (mark) (point))))
  1327.   (ps-nb-pages nb-lines))
  1328.  
  1329. ;;;###autoload
  1330. (defun ps-setup ()
  1331.   "*Return the current setup"
  1332.   (format "
  1333.  (setq ps-print-color-p  %s
  1334.       ps-lpr-command    \"%s\"
  1335.       ps-lpr-switches   %s
  1336.  
  1337.       ps-paper-type       '%s
  1338.       ps-landscape-mode   %s
  1339.       ps-number-of-columns %s
  1340.  
  1341.       ps-left-margin   %s
  1342.       ps-right-margin  %s
  1343.       ps-inter-column  %s
  1344.       ps-bottom-margin %s
  1345.       ps-top-margin    %s
  1346.       ps-header-offset %s
  1347.       ps-header-line-pad    %s
  1348.       ps-print-header       %s
  1349.       ps-print-header-frame %s
  1350.       ps-header-lines       %s
  1351.       ps-show-n-of-n        %s
  1352.       ps-spool-duplex       %s
  1353.  
  1354.       ps-font-family             '%s
  1355.       ps-font-size               %s
  1356.       ps-header-font-family      '%s
  1357.       ps-header-font-size        %s
  1358.       ps-header-title-font-size  %s)
  1359. "
  1360.   ps-print-color-p
  1361.   ps-lpr-command
  1362.   ps-lpr-switches
  1363.   ps-paper-type
  1364.   ps-landscape-mode
  1365.   ps-number-of-columns
  1366.   ps-left-margin
  1367.   ps-right-margin
  1368.   ps-inter-column
  1369.   ps-bottom-margin
  1370.   ps-top-margin
  1371.   ps-header-offset
  1372.   ps-header-line-pad
  1373.   ps-print-header
  1374.   ps-print-header-frame
  1375.   ps-header-lines
  1376.   ps-show-n-of-n
  1377.   ps-spool-duplex
  1378.   ps-font-family
  1379.   ps-font-size
  1380.   ps-header-font-family
  1381.   ps-header-font-size
  1382.   ps-header-title-font-size))
  1383.  
  1384. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1385. ;; Utility functions and variables:
  1386.  
  1387. (defvar ps-print-emacs-type
  1388.   (cond ((string-match "XEmacs" emacs-version) 'xemacs)
  1389.     ((string-match "Lucid" emacs-version) 'lucid)
  1390.     ((string-match "Epoch" emacs-version) 'epoch)
  1391.     (t 'emacs)))
  1392.  
  1393. (if (or (eq ps-print-emacs-type 'lucid)
  1394.     (eq ps-print-emacs-type 'xemacs))
  1395.     (if (< emacs-minor-version 12)
  1396.     (setq ps-print-color-p nil))
  1397.   (require 'faces))            ; face-font, face-underline-p,
  1398.                     ; x-font-regexp
  1399.  
  1400. ;; Return t if the device (which can be changed during an emacs
  1401. ;; session) can handle colors.  
  1402. ;; This is function is not yet implemented for GNU emacs.
  1403. (defun ps-color-device ()
  1404.   (if (and (eq ps-print-emacs-type 'xemacs)
  1405.        (>= emacs-minor-version 12))
  1406.       (eq (device-class) 'color)
  1407.     t))
  1408.  
  1409. (require 'time-stamp)
  1410.  
  1411. (defvar ps-font nil
  1412.   "Font family name for ordinary text, when generating Postscript.")
  1413.  
  1414. (defvar ps-font-bold nil
  1415.   "Font family name for bold text, when generating Postscript.")
  1416.  
  1417. (defvar ps-font-italic nil
  1418.   "Font family name for italic text, when generating Postscript.")
  1419.  
  1420. (defvar ps-font-bold-italic nil
  1421.   "Font family name for bold italic text, when generating Postscript.")
  1422.  
  1423. (defvar ps-avg-char-width nil
  1424.   "The average width, in points, of a character, for generating Postscript.
  1425. This is the value that ps-print uses to determine the length,
  1426. x-dimension, of the text it has printed, and thus affects the point at
  1427. which long lines wrap around.")
  1428.  
  1429. (defvar ps-space-width nil
  1430.   "The width of a space character, for generating Postscript.
  1431. This value is used in expanding tab characters.")
  1432.  
  1433. (defvar ps-line-height nil
  1434.   "The height of a line, for generating Postscript.
  1435. This is the value that ps-print uses to determine the height,
  1436. y-dimension, of the lines of text it has printed, and thus affects the
  1437. point at which page-breaks are placed.
  1438. The line-height is *not* the same as the point size of the font.")
  1439.  
  1440. (defvar ps-print-prologue-1
  1441.   "% ISOLatin1Encoding stolen from ps_init.ps in GhostScript 2.6.1.4:
  1442. /ISOLatin1Encoding where { pop } {
  1443. % -- The ISO Latin-1 encoding vector isn't known, so define it.
  1444. % -- The first half is the same as the standard encoding,
  1445. % -- except for minus instead of hyphen at code 055.
  1446. /ISOLatin1Encoding
  1447. StandardEncoding 0 45 getinterval aload pop
  1448.     /minus
  1449. StandardEncoding 46 82 getinterval aload pop
  1450. %*** NOTE: the following are missing in the Adobe documentation,
  1451. %*** but appear in the displayed table:
  1452. %*** macron at 0225, dieresis at 0230, cedilla at 0233, space at 0240.
  1453. % 0200 (128)
  1454.     /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
  1455.     /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef /.notdef
  1456.     /dotlessi /grave /acute /circumflex /tilde /macron /breve /dotaccent
  1457.     /dieresis /.notdef /ring /cedilla /.notdef /hungarumlaut /ogonek /caron
  1458. % 0240 (160)
  1459.     /space /exclamdown /cent /sterling
  1460.     /currency /yen /brokenbar /section
  1461.     /dieresis /copyright /ordfeminine /guillemotleft
  1462.     /logicalnot /hyphen /registered /macron
  1463.     /degree /plusminus /twosuperior /threesuperior
  1464.     /acute /mu /paragraph /periodcentered
  1465.     /cedilla /onesuperior /ordmasculine /guillemotright
  1466.     /onequarter /onehalf /threequarters /questiondown
  1467. % 0300 (192)
  1468.     /Agrave /Aacute /Acircumflex /Atilde
  1469.     /Adieresis /Aring /AE /Ccedilla
  1470.     /Egrave /Eacute /Ecircumflex /Edieresis
  1471.     /Igrave /Iacute /Icircumflex /Idieresis
  1472.     /Eth /Ntilde /Ograve /Oacute
  1473.     /Ocircumflex /Otilde /Odieresis /multiply
  1474.     /Oslash /Ugrave /Uacute /Ucircumflex
  1475.     /Udieresis /Yacute /Thorn /germandbls
  1476. % 0340 (224)
  1477.     /agrave /aacute /acircumflex /atilde
  1478.     /adieresis /aring /ae /ccedilla
  1479.     /egrave /eacute /ecircumflex /edieresis
  1480.     /igrave /iacute /icircumflex /idieresis
  1481.     /eth /ntilde /ograve /oacute
  1482.     /ocircumflex /otilde /odieresis /divide
  1483.     /oslash /ugrave /uacute /ucircumflex
  1484.     /udieresis /yacute /thorn /ydieresis
  1485. 256 packedarray def
  1486. } ifelse
  1487.  
  1488. /reencodeFontISO { %def
  1489.   dup
  1490.   length 5 add dict    % Make a new font (a new dict the same size
  1491.             % as the old one) with room for our new symbols.
  1492.  
  1493.   begin            % Make the new font the current dictionary.
  1494.  
  1495.  
  1496.     { 1 index /FID ne
  1497.       { def } { pop pop } ifelse
  1498.     } forall        % Copy each of the symbols from the old dictionary
  1499.             % to the new one except for the font ID.
  1500.  
  1501.     /Encoding ISOLatin1Encoding def    % Override the encoding with
  1502.                     % the ISOLatin1 encoding.
  1503.  
  1504.     % Use the font's bounding box to determine the ascent, descent,
  1505.     % and overall height; don't forget that these values have to be
  1506.     % transformed using the font's matrix.
  1507.  
  1508. %          ^    (x2 y2)
  1509. %          |       |
  1510. %          |       v
  1511. %          |  +----+ - -
  1512. %          |  |    |   ^
  1513. %          |  |    |   | Ascent (usually > 0)
  1514. %          |  |    |   |
  1515. % (0 0) -> +--+----+-------->
  1516. %             |    |   |
  1517. %             |    |   v Descent (usually < 0)
  1518. % (x1 y1) --> +----+ - -
  1519.  
  1520.     FontBBox                % -- x1 y1 x2 y2
  1521.     FontMatrix transform /Ascent  exch def pop
  1522.     FontMatrix transform /Descent exch def pop
  1523.     /FontHeight Ascent Descent sub def    % use `sub' because descent < 0
  1524.  
  1525.     % Define these in case they're not in the FontInfo
  1526.     % (also, here they're easier to get to.
  1527.     /UnderlinePosition  1 def
  1528.     /UnderlineThickness 1 def
  1529.  
  1530.     % Get the underline position and thickness if they're defined.
  1531.     currentdict /FontInfo known {
  1532.       FontInfo
  1533.  
  1534.       dup /UnderlinePosition known {
  1535.     dup /UnderlinePosition get
  1536.     0 exch FontMatrix transform exch pop
  1537.     /UnderlinePosition exch def
  1538.       } if
  1539.  
  1540.       dup /UnderlineThickness known {
  1541.     /UnderlineThickness get
  1542.     0 exch FontMatrix transform exch pop
  1543.     /UnderlineThickness exch def
  1544.       } if
  1545.  
  1546.     } if
  1547.  
  1548.     currentdict        % Leave the new font on the stack
  1549.     end            % Stop using the font as the current dictionary.
  1550.     definefont        % Put the font into the font dictionary
  1551.     pop            % Discard the returned font.
  1552. } bind def
  1553.  
  1554. /DefFont {                % Font definition
  1555.   findfont exch scalefont reencodeFontISO
  1556. } def
  1557.  
  1558. /F {                    % Font selection
  1559.   findfont
  1560.   dup /Ascent             get /Ascent             exch def
  1561.   dup /Descent            get /Descent            exch def
  1562.   dup /FontHeight         get /FontHeight         exch def
  1563.   dup /UnderlinePosition  get /UnderlinePosition  exch def
  1564.   dup /UnderlineThickness get /UnderlineThickness exch def
  1565.   setfont
  1566. } def
  1567.  
  1568. /FG /setrgbcolor load def
  1569.  
  1570. /bg false def
  1571. /BG {
  1572.   dup /bg exch def
  1573.   { mark 4 1 roll ] /bgcolor exch def } if
  1574. } def
  1575.  
  1576. %  B    width    C
  1577. %   +-----------+
  1578. %               | Ascent  (usually > 0)
  1579. % A +           +
  1580. %               | Descent (usually < 0)
  1581. %   +-----------+
  1582. %  E    width    D
  1583.  
  1584. /dobackground {                % width --
  1585.   currentpoint                % -- width x y
  1586.   gsave
  1587.     newpath
  1588.     moveto                % A (x y)
  1589.     0 Ascent rmoveto            % B
  1590.     dup 0 rlineto            % C
  1591.     0 Descent Ascent sub rlineto    % D
  1592.     neg 0 rlineto            % E
  1593.     closepath
  1594.     bgcolor aload pop setrgbcolor
  1595.     fill
  1596.   grestore
  1597. } def
  1598.  
  1599. /dobackgroundstring {            % string --
  1600.   stringwidth pop
  1601.   dobackground
  1602. } def
  1603.  
  1604. /dounderline {                % fromx fromy --
  1605.   currentpoint
  1606.   gsave
  1607.     UnderlineThickness setlinewidth
  1608.     4 2 roll
  1609.     UnderlinePosition add moveto
  1610.     UnderlinePosition add lineto
  1611.     stroke
  1612.   grestore
  1613. } def
  1614.  
  1615. /eolbg {                % dobackground until right margin
  1616.   PrintWidth                % -- x-eol
  1617.   currentpoint pop            % -- cur-x
  1618.   sub                    % -- width until eol
  1619.   dobackground
  1620. } def
  1621.  
  1622. /eolul {                % idem for underline
  1623.   PrintWidth                % -- x-eol
  1624.   currentpoint exch pop            % -- x-eol cur-y
  1625.   dounderline
  1626. } def
  1627.  
  1628. /SL {                    % Soft Linefeed
  1629.   bg { eolbg } if
  1630.   ul { eolul } if
  1631.   0  currentpoint exch pop LineHeight sub  moveto
  1632. } def
  1633.  
  1634. /HL /SL load def            % Hard Linefeed
  1635.  
  1636. /sp1 { currentpoint 3 -1 roll } def
  1637.  
  1638. % Some debug
  1639. /dcp { currentpoint exch 40 string cvs print (, ) print = } def
  1640. /dp { print 2 copy
  1641.    exch 40 string cvs print (, ) print = } def
  1642.  
  1643. /S {
  1644.   bg { dup dobackgroundstring } if
  1645.   ul { sp1 } if
  1646.   show
  1647.   ul { dounderline } if
  1648. } def
  1649.  
  1650. /W {
  1651.   ul { sp1 } if
  1652.   ( ) stringwidth    % Get the width of a space in the current font.
  1653.   pop            % Discard the Y component.
  1654.   mul            % Multiply the width of a space
  1655.             % by the number of spaces to plot
  1656.   bg { dup dobackground } if
  1657.   0 rmoveto
  1658.   ul { dounderline } if
  1659. } def
  1660.  
  1661. /BeginDoc {
  1662.   % ---- save the state of the document (useful for ghostscript!)
  1663.   /docState save def
  1664.   % ---- [jack] Kludge: my ghostscript window is 21x27.7 instead of 21x29.7
  1665.   /JackGhostscript where {
  1666.     pop 1 27.7 29.7 div scale
  1667.   } if
  1668.   LandscapeMode {
  1669.     % ---- translate to bottom-right corner of Portrait page
  1670.     LandscapePageHeight 0 translate
  1671.     90 rotate
  1672.     } if
  1673.   /ColumnWidth PrintWidth InterColumn add def
  1674.   % ---- translate to lower left corner of TEXT
  1675.   LeftMargin BottomMargin translate
  1676.   % ---- define where  printing will start
  1677.   /f0 F                    % this installs Ascent
  1678.   /PrintStartY PrintHeight Ascent sub def
  1679.   /ColumnIndex 1 def
  1680. } def
  1681.  
  1682. /EndDoc {
  1683.   % ---- on last page but not last column, spit out the page
  1684.   ColumnIndex 1 eq not { showpage } if
  1685.   % ---- restore the state of the document (useful for ghostscript!)
  1686.   docState restore
  1687. } def
  1688.  
  1689. /BeginDSCPage {
  1690.   % ---- when 1st column, save the state of the page
  1691.   ColumnIndex 1 eq { /pageState save def } if
  1692.   % ---- save the state of the column
  1693.   /columnState save def
  1694. } def
  1695.  
  1696. /BeginPage {
  1697.   PrintHeader {
  1698.     PrintHeaderFrame { HeaderFrame } if
  1699.     HeaderText
  1700.   } if
  1701.   0 PrintStartY moveto            % move to where printing will start
  1702. } def
  1703.  
  1704. /EndPage {
  1705.   bg { eolbg } if
  1706.   ul { eolul } if
  1707. } def
  1708.  
  1709. /EndDSCPage {
  1710.   ColumnIndex NumberOfColumns eq {
  1711.     % ---- on last column, spit out the page
  1712.     showpage
  1713.     % ---- restore the state of the page
  1714.     pageState restore
  1715.     /ColumnIndex 1 def
  1716.   } { % else
  1717.     % ---- restore the state of the current column
  1718.     columnState restore
  1719.     % ---- and translate to the next column
  1720.     ColumnWidth 0 translate
  1721.     /ColumnIndex ColumnIndex 1 add def
  1722.   } ifelse
  1723. } def
  1724.  
  1725. /ul false def
  1726.  
  1727. /UL { /ul exch def } def
  1728.  
  1729. /SetHeaderLines {            % nb-lines --
  1730.   /HeaderLines exch def
  1731.   % ---- bottom up
  1732.   HeaderPad
  1733.   HeaderLines 1 sub HeaderLineHeight mul add
  1734.   HeaderTitleLineHeight add
  1735.   HeaderPad add
  1736.   /HeaderHeight exch def
  1737. } def
  1738.  
  1739. % |---------|
  1740. % |  tm     |
  1741. % |---------|
  1742. % |  header |
  1743. % |-+-------| <-- (x y)
  1744. % |  ho     |
  1745. % |---------|
  1746. % |  text   |
  1747. % |-+-------| <-- (0 0)
  1748. % |  bm     |
  1749. % |---------|
  1750.  
  1751. /HeaderFrameStart {            % -- x y
  1752.   0  PrintHeight HeaderOffset add
  1753. } def
  1754.  
  1755. /HeaderFramePath {
  1756.   PrintWidth     0            rlineto
  1757.   0         HeaderHeight        rlineto
  1758.   PrintWidth neg 0            rlineto
  1759.   0         HeaderHeight neg    rlineto
  1760. } def
  1761.  
  1762. /HeaderFrame {
  1763.   gsave
  1764.     0.4 setlinewidth
  1765.     % ---- fill a black rectangle (the shadow of the next one)
  1766.     HeaderFrameStart moveto
  1767.     1 -1 rmoveto
  1768.     HeaderFramePath
  1769.     0 setgray fill
  1770.     % ---- do the next rectangle ...
  1771.     HeaderFrameStart moveto
  1772.     HeaderFramePath
  1773.     gsave 0.9 setgray fill grestore    % filled with grey
  1774.     gsave 0 setgray stroke grestore    % drawn  with black
  1775.   grestore
  1776. } def
  1777.  
  1778. /HeaderStart {
  1779.   HeaderFrameStart
  1780.   exch HeaderPad add exch    % horizontal pad
  1781.   % ---- bottom up
  1782.   HeaderPad add            % vertical   pad
  1783.   HeaderDescent sub
  1784.   HeaderLineHeight HeaderLines 1 sub mul add
  1785. } def
  1786.  
  1787. /strcat {
  1788.   dup length 3 -1 roll dup length dup 4 -1 roll add string dup
  1789.   0 5 -1 roll putinterval
  1790.   dup 4 2 roll exch putinterval
  1791. } def
  1792.  
  1793. /pagenumberstring {
  1794.   PageNumber 32 string cvs
  1795.   ShowNofN {
  1796.     (/) strcat
  1797.     PageCount 32 string cvs strcat
  1798.   } if
  1799. } def
  1800.  
  1801. /HeaderText {
  1802.   HeaderStart moveto
  1803.  
  1804.   HeaderLinesRight HeaderLinesLeft    % -- rightLines leftLines
  1805.  
  1806.   % ---- hack: `PN 1 and'  ==  `PN 2 modulo'
  1807.  
  1808.   % ---- if duplex and even page number, then exchange left and right
  1809.   Duplex PageNumber 1 and 0 eq and { exch } if
  1810.  
  1811.   { % ---- process the left lines
  1812.     aload pop
  1813.     exch F
  1814.     gsave
  1815.       dup xcheck { exec } if
  1816.       show
  1817.     grestore
  1818.     0 HeaderLineHeight neg rmoveto
  1819.   } forall
  1820.  
  1821.   HeaderStart moveto
  1822.  
  1823.   { % ---- process the right lines
  1824.     aload pop
  1825.     exch F
  1826.     gsave
  1827.       dup xcheck { exec } if
  1828.       dup stringwidth pop
  1829.       PrintWidth exch sub HeaderPad 2 mul sub 0 rmoveto
  1830.       show
  1831.     grestore
  1832.     0 HeaderLineHeight neg rmoveto
  1833.   } forall
  1834. } def
  1835.  
  1836. /ReportFontInfo {
  1837.   2 copy
  1838.   /t0 3 1 roll DefFont
  1839.   /t0 F
  1840.   /lh FontHeight def
  1841.   /sw ( ) stringwidth pop def
  1842.   /aw (01234567890abcdefghijklmnopqrstuvwxyz) dup length exch
  1843.   stringwidth pop exch div def
  1844.   /t1 12 /Helvetica-Oblique DefFont
  1845.   /t1 F
  1846.   gsave
  1847.     (For ) show
  1848.     128 string cvs show
  1849.     ( ) show
  1850.     32 string cvs show
  1851.     ( point, the line height is ) show
  1852.     lh 32 string cvs show
  1853.     (, the space width is ) show
  1854.     sw 32 string cvs show
  1855.     (,) show
  1856.   grestore
  1857.   0 FontHeight neg rmoveto
  1858.   gsave
  1859.     (and a crude estimate of average character width is ) show
  1860.     aw 32 string cvs show
  1861.     (.) show
  1862.   grestore
  1863.   0 FontHeight neg rmoveto
  1864. } def
  1865.  
  1866. /cm { % cm to point
  1867.   72 mul 2.54 div
  1868. } def
  1869.  
  1870. /ReportAllFontInfo {
  1871.   FontDirectory
  1872.   { % key = font name  value = font dictionary
  1873.     pop 10 exch ReportFontInfo
  1874.   } forall
  1875. } def
  1876.  
  1877. % 3 cm 20 cm moveto  10 /Courier ReportFontInfo  showpage
  1878. % 3 cm 20 cm moveto  ReportAllFontInfo           showpage
  1879.  
  1880. ")
  1881.  
  1882. (defvar ps-print-prologue-2
  1883.   "
  1884. % ---- These lines must be kept together because...
  1885.  
  1886. /h0 F
  1887. /HeaderTitleLineHeight FontHeight def
  1888.  
  1889. /h1 F
  1890. /HeaderLineHeight FontHeight def
  1891. /HeaderDescent    Descent def
  1892.  
  1893. % ---- ...because `F' has a side-effect on `FontHeight' and `Descent'
  1894.  
  1895. ")
  1896.  
  1897. ;; Start Editing Here:
  1898.  
  1899. (defvar ps-source-buffer nil)
  1900. (defvar ps-spool-buffer-name "*PostScript*")
  1901. (defvar ps-spool-buffer nil)
  1902.  
  1903. (defvar ps-output-head nil)
  1904. (defvar ps-output-tail nil)
  1905.  
  1906. (defvar ps-page-count 0)
  1907. (defvar ps-showpage-count 0)
  1908.  
  1909. (defvar ps-current-font 0)
  1910. (defvar ps-current-underline-p nil)
  1911. (defvar ps-default-color (if ps-print-color-p ps-default-fg)) ; black
  1912. (defvar ps-current-color ps-default-color)
  1913. (defvar ps-current-bg nil)
  1914.  
  1915. (defvar ps-razchunk 0)
  1916.  
  1917. (defvar ps-color-format
  1918.   (if (eq ps-print-emacs-type 'emacs)
  1919.  
  1920.     ;;Emacs understands the %f format; we'll
  1921.     ;;use it to limit color RGB values to
  1922.     ;;three decimals to cut down some on the
  1923.     ;;size of the PostScript output.
  1924.     "%0.3f %0.3f %0.3f"
  1925.  
  1926.     ;; Lucid emacsen will have to make do with
  1927.     ;; %s (princ) for floats.
  1928.     "%s %s %s"))
  1929.  
  1930. ;; These values determine how much print-height to deduct when headers
  1931. ;; are turned on.  This is a pretty clumsy way of handling it, but
  1932. ;; it'll do for now.
  1933.  
  1934. (defvar ps-header-font)
  1935. (defvar ps-header-title-font)
  1936.  
  1937. (defvar ps-header-line-height)
  1938. (defvar ps-header-title-line-height)
  1939. (defvar ps-header-pad 0
  1940.   "Vertical and horizontal space in points (1/72 inch) between the header frame
  1941. and the text it contains.")
  1942.  
  1943. ;; Define accessors to the dimensions list.
  1944.  
  1945. (defmacro ps-page-dimensions-get-width  (dims) `(nth 0 ,dims))
  1946. (defmacro ps-page-dimensions-get-height (dims) `(nth 1 ,dims))
  1947.  
  1948. (defvar ps-landscape-page-height)
  1949.  
  1950. (defvar ps-print-width nil)
  1951. (defvar ps-print-height nil)
  1952.  
  1953. (defvar ps-height-remaining)
  1954. (defvar ps-width-remaining)
  1955.  
  1956. (defvar ps-ref-bold-faces nil)
  1957. (defvar ps-ref-italic-faces nil)
  1958. (defvar ps-ref-underlined-faces nil)
  1959.  
  1960. (defvar ps-print-color-scale nil)
  1961.  
  1962. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1963. ;; Internal functions
  1964.  
  1965. (defun ps-line-lengths-internal ()
  1966.   "Display the correspondence between a line length and a font size,
  1967. using the current ps-print setup.
  1968. Try: pr -t file | awk '{printf \"%3d %s\n\", length($0), $0}' | sort -r | head"
  1969.   (let ((buf (get-buffer-create "*Line-lengths*"))
  1970.     (ifs ps-font-size)        ; initial font size
  1971.     (icw ps-avg-char-width)        ; initial character width
  1972.     (print-width (progn (ps-get-page-dimensions)
  1973.                 ps-print-width))
  1974.     (ps-setup (ps-setup))        ; setup for the current buffer
  1975.     (fs-min 5)            ; minimum font size
  1976.     cw-min                ; minimum character width
  1977.     nb-cpl-max            ; maximum nb of characters per line
  1978.     (fs-max 14)            ; maximum font size
  1979.     cw-max                ; maximum character width
  1980.     nb-cpl-min            ; minimum nb of characters per line
  1981.     fs                ; current font size
  1982.     cw                ; current character width
  1983.     nb-cpl                ; current nb of characters per line
  1984.     )
  1985.     (setq cw-min     (/ (* icw fs-min) ifs)
  1986.       nb-cpl-max (floor (/ print-width cw-min))
  1987.       cw-max     (/ (* icw fs-max) ifs)
  1988.       nb-cpl-min (floor (/ print-width cw-max)))
  1989.     (setq nb-cpl nb-cpl-min)
  1990.     (set-buffer buf)
  1991.     (goto-char (point-max))
  1992.     (if (not (bolp)) (insert "\n"))
  1993.     (insert ps-setup)
  1994.     (insert "nb char per line / font size\n")
  1995.     (while (<= nb-cpl nb-cpl-max)
  1996.       (setq cw     (/ print-width (float nb-cpl))
  1997.         fs     (/ (* ifs cw) icw))
  1998.       (insert (format "%3s %s\n" nb-cpl fs))
  1999.       (setq nb-cpl (1+ nb-cpl)))
  2000.     (insert "\n")
  2001.     (display-buffer buf 'not-this-window)))
  2002.  
  2003. (defun ps-nb-pages (nb-lines)
  2004.   "Display an approximate correspondence between a font size and the number
  2005. of pages the number of lines would require to print
  2006. using the current ps-print setup."
  2007.   (let ((buf (get-buffer-create "*Nb-Pages*"))
  2008.     (ifs ps-font-size)        ; initial font size
  2009.     (ilh ps-line-height)        ; initial line height
  2010.     (page-height (progn (ps-get-page-dimensions)
  2011.                 ps-print-height))
  2012.     (ps-setup (ps-setup))        ; setup for the current buffer
  2013.     (fs-min 4)            ; minimum font size
  2014.     lh-min                ; minimum line height
  2015.     nb-lpp-max            ; maximum nb of lines per page
  2016.     nb-page-min            ; minimum nb of pages
  2017.     (fs-max 14)            ; maximum font size
  2018.     lh-max                ; maximum line height
  2019.     nb-lpp-min            ; minimum nb of lines per page
  2020.     nb-page-max            ; maximum nb of pages
  2021.     fs                ; current font size
  2022.     lh                ; current line height
  2023.     nb-lpp                ; current nb of lines per page
  2024.     nb-page                ; current nb of pages
  2025.     )
  2026.     (setq lh-min      (/ (* ilh fs-min) ifs)
  2027.       nb-lpp-max  (floor (/ page-height lh-min))
  2028.       nb-page-min (ceiling (/ (float nb-lines) nb-lpp-max))
  2029.       lh-max      (/ (* ilh fs-max) ifs)
  2030.       nb-lpp-min  (floor (/ page-height lh-max))
  2031.       nb-page-max (ceiling (/ (float nb-lines) nb-lpp-min)))
  2032.     (setq nb-page nb-page-min)
  2033.     (set-buffer buf)
  2034.     (goto-char (point-max))
  2035.     (if (not (bolp)) (insert "\n"))
  2036.     (insert ps-setup)
  2037.     (insert (format "%d lines\n" nb-lines))
  2038.     (insert "nb page / font size\n")
  2039.     (while (<= nb-page nb-page-max)
  2040.       (setq nb-lpp (ceiling (/ nb-lines (float nb-page)))
  2041.         lh     (/ page-height nb-lpp)
  2042.         fs     (/ (* ifs lh) ilh))
  2043.       (insert (format "%s %s\n" nb-page fs))
  2044.       (setq nb-page (1+ nb-page)))
  2045.     (insert "\n")
  2046.     (display-buffer buf 'not-this-window)))
  2047.  
  2048. (defun ps-select-font ()
  2049.   "Choose the font name and size (scaling data)."
  2050.   (let ((assoc (assq ps-font-family ps-font-info-database))
  2051.     l fn fb fi bi sz lh sw aw)
  2052.     (if (null assoc)
  2053.     (error "Don't have data to scale font %s. Known fonts families are %s"
  2054.            ps-font-family
  2055.            (mapcar 'car ps-font-info-database)))
  2056.     (setq l  (cdr assoc)
  2057.       fn (prog1 (car l) (setq l (cdr l))) ; need `pop'
  2058.       fb (prog1 (car l) (setq l (cdr l)))
  2059.       fi (prog1 (car l) (setq l (cdr l)))
  2060.       bi (prog1 (car l) (setq l (cdr l)))
  2061.       sz (prog1 (car l) (setq l (cdr l)))
  2062.       lh (prog1 (car l) (setq l (cdr l)))
  2063.       sw (prog1 (car l) (setq l (cdr l)))
  2064.       aw (prog1 (car l) (setq l (cdr l))))
  2065.  
  2066.     (setq ps-font             fn)
  2067.     (setq ps-font-bold        fb)
  2068.     (setq ps-font-italic      fi)
  2069.     (setq ps-font-bold-italic bi)
  2070.     ;; These data just need to be rescaled:
  2071.     (setq ps-line-height    (/ (* lh ps-font-size) sz))
  2072.     (setq ps-space-width    (/ (* sw ps-font-size) sz))
  2073.     (setq ps-avg-char-width (/ (* aw ps-font-size) sz))
  2074.     ps-font-family))
  2075.  
  2076. (defun ps-select-header-font ()
  2077.   "Choose the font name and size (scaling data) for the header."
  2078.   (let ((assoc (assq ps-header-font-family ps-font-info-database))
  2079.     l fn fb fi bi sz lh sw aw)
  2080.     (if (null assoc)
  2081.     (error "Don't have data to scale font %s. Known fonts families are %s"
  2082.            ps-font-family
  2083.            (mapcar 'car ps-font-info-database)))
  2084.     (setq l  (cdr assoc)
  2085.       fn (prog1 (car l) (setq l (cdr l))) ; need `pop'
  2086.       fb (prog1 (car l) (setq l (cdr l)))
  2087.       fi (prog1 (car l) (setq l (cdr l)))
  2088.       bi (prog1 (car l) (setq l (cdr l)))
  2089.       sz (prog1 (car l) (setq l (cdr l)))
  2090.       lh (prog1 (car l) (setq l (cdr l)))
  2091.       sw (prog1 (car l) (setq l (cdr l)))
  2092.       aw (prog1 (car l) (setq l (cdr l))))
  2093.  
  2094.     ;; Font name
  2095.     (setq ps-header-font             fn)
  2096.     (setq ps-header-title-font       fb)
  2097.     ;; Line height: These data just need to be rescaled:
  2098.     (setq ps-header-title-line-height (/ (* lh ps-header-title-font-size) sz))
  2099.     (setq ps-header-line-height       (/ (* lh ps-header-font-size)       sz))
  2100.     ps-header-font-family))
  2101.  
  2102. (defun ps-get-page-dimensions ()
  2103.   (let ((page-dimensions (cdr (assq ps-paper-type ps-page-dimensions-database)))
  2104.     page-width page-height)
  2105.     (cond
  2106.      ((null page-dimensions)
  2107.       (error "`ps-paper-type' must be one of:\n%s"
  2108.          (mapcar 'car ps-page-dimensions-database)))
  2109.      ((< ps-number-of-columns 1)
  2110.       (error "The number of columns %d should not be negative")))
  2111.  
  2112.     (ps-select-font)
  2113.     (ps-select-header-font)
  2114.  
  2115.     (setq page-width  (ps-page-dimensions-get-width  page-dimensions)
  2116.       page-height (ps-page-dimensions-get-height page-dimensions))
  2117.  
  2118.     ;; Landscape mode
  2119.     (if ps-landscape-mode
  2120.     ;; exchange width and height
  2121.     (setq page-width (prog1 page-height (setq page-height page-width))))
  2122.  
  2123.     ;; It is used to get the lower right corner (only in landscape mode)
  2124.     (setq ps-landscape-page-height page-height)
  2125.  
  2126.     ;; | lm | text | ic | text | ic | text | rm |
  2127.     ;; page-width == lm  +  n * pw  +  (n - 1) * ic  +  rm
  2128.     ;; => pw == (page-width - lm -rm - (n - 1) * ic) / n
  2129.     (setq ps-print-width
  2130.       (/ (- page-width
  2131.         ps-left-margin ps-right-margin
  2132.         (* (1- ps-number-of-columns) ps-inter-column))
  2133.          ps-number-of-columns))
  2134.     (if (<= ps-print-width 0)
  2135.     (error "Bad horizontal layout:
  2136. page-width           == %s
  2137. ps-left-margin       == %s
  2138. ps-right-margin      == %s
  2139. ps-inter-column      == %s
  2140. ps-number-of-columns == %s
  2141. | lm | text | ic | text | ic | text | rm |
  2142. page-width == lm  +  n * print-width  +  (n - 1) * ic  +  rm
  2143. => print-width == %d !"
  2144.            page-width
  2145.            ps-left-margin
  2146.            ps-right-margin
  2147.            ps-inter-column
  2148.            ps-number-of-columns
  2149.            ps-print-width))
  2150.  
  2151.     (setq ps-print-height
  2152.       (- page-height ps-bottom-margin ps-top-margin))
  2153.     (if (<= ps-print-height 0)
  2154.     (error "Bad vertical layout:
  2155. ps-top-margin    == %s
  2156. ps-bottom-margin == %s
  2157. page-height == bm + print-height + tm
  2158. => print-height == %d !"
  2159.            ps-top-margin
  2160.            ps-bottom-margin
  2161.            ps-print-height))
  2162.     ;; If headers are turned on, deduct the height of the header from
  2163.     ;; the print height.
  2164.     (cond
  2165.      (ps-print-header
  2166.       (setq ps-header-pad
  2167.         (* ps-header-line-pad ps-header-title-line-height))
  2168.       (setq ps-print-height
  2169.         (- ps-print-height
  2170.            ps-header-offset
  2171.            ps-header-pad
  2172.            ps-header-title-line-height
  2173.            (* ps-header-line-height (- ps-header-lines 1))
  2174.            ps-header-pad))))
  2175.     (if (<= ps-print-height 0)
  2176.     (error "Bad vertical layout:
  2177. ps-top-margin    == %s
  2178. ps-bottom-margin == %s
  2179. ps-header-offset == %s
  2180. ps-header-pad    == %s
  2181. header-height    == %s
  2182. page-height == bm + print-height + tm - ho - hh
  2183. => print-height == %d !"
  2184.            ps-top-margin
  2185.            ps-bottom-margin
  2186.            ps-header-offset
  2187.            ps-header-pad
  2188.            (+ ps-header-pad
  2189.           ps-header-title-line-height
  2190.           (* ps-header-line-height (- ps-header-lines 1))
  2191.           ps-header-pad)
  2192.            ps-print-height))))
  2193.  
  2194. (defun ps-print-preprint (&optional filename)
  2195.   (if (and filename
  2196.        (or (numberp filename)
  2197.            (listp filename)))
  2198.       (let* ((name (concat (buffer-name) ".ps"))
  2199.          (prompt (format "Save PostScript to file: (default %s) "
  2200.                  name))
  2201.          (res (read-file-name prompt default-directory name nil)))
  2202.     (if (file-directory-p res)
  2203.         (expand-file-name name (file-name-as-directory res))
  2204.       res))))
  2205.  
  2206. ;; The following functions implement a simple list-buffering scheme so
  2207. ;; that ps-print doesn't have to repeatedly switch between buffers
  2208. ;; while spooling.  The functions ps-output and ps-output-string build
  2209. ;; up the lists; the function ps-flush-output takes the lists and
  2210. ;; insert its contents into the spool buffer (*PostScript*).
  2211.  
  2212. (defun ps-output-string-prim (string)
  2213.   (insert "(")                ;insert start-string delimiter
  2214.   (save-excursion            ;insert string
  2215.     (insert string))
  2216.  
  2217.   ;; Find and quote special characters as necessary for PS
  2218.   (while (re-search-forward "[()\\]" nil t)
  2219.     (save-excursion
  2220.       (forward-char -1)
  2221.       (insert "\\")))
  2222.  
  2223.   (goto-char (point-max))
  2224.   (insert ")"))                ;insert end-string delimiter
  2225.  
  2226. (defun ps-init-output-queue ()
  2227.   (setq ps-output-head (list ""))
  2228.   (setq ps-output-tail ps-output-head))
  2229.  
  2230. (defun ps-output (&rest args)
  2231.   (setcdr ps-output-tail args)
  2232.   (while (cdr ps-output-tail)
  2233.     (setq ps-output-tail (cdr ps-output-tail))))
  2234.  
  2235. (defun ps-output-string (string)
  2236.   (ps-output t string))
  2237.  
  2238. (defun ps-flush-output ()
  2239.   (save-excursion
  2240.     (set-buffer ps-spool-buffer)
  2241.     (goto-char (point-max))
  2242.     (while ps-output-head
  2243.       (let ((it (car ps-output-head)))
  2244.     (if (not (eq t it))
  2245.         (insert it)
  2246.       (setq ps-output-head (cdr ps-output-head))
  2247.       (ps-output-string-prim (car ps-output-head))))
  2248.       (setq ps-output-head (cdr ps-output-head))))
  2249.   (ps-init-output-queue))
  2250.  
  2251. (defun ps-insert-file (fname)
  2252.   (ps-flush-output)
  2253.  
  2254.   ;; Check to see that the file exists and is readable; if not, throw
  2255.   ;; an error.
  2256.   (if (not (file-readable-p fname))
  2257.       (error "Could not read file `%s'" fname))
  2258.  
  2259.   (save-excursion
  2260.     (set-buffer ps-spool-buffer)
  2261.     (goto-char (point-max))
  2262.     (insert-file fname)))
  2263.     
  2264. ;; These functions insert the arrays that define the contents of the
  2265. ;; headers.
  2266.  
  2267. (defun ps-generate-header-line (fonttag &optional content)
  2268.   (ps-output "  [ " fonttag " ")
  2269.   (cond
  2270.    ;; Literal strings should be output as is -- the string must
  2271.    ;; contain its own PS string delimiters, '(' and ')', if necessary.
  2272.    ((stringp content)
  2273.     (ps-output content))
  2274.  
  2275.    ;; Functions are called -- they should return strings; they will be
  2276.    ;; inserted as strings and the PS string delimiters added.
  2277.    ((and (symbolp content) (fboundp content))
  2278.     (ps-output-string (funcall content)))
  2279.  
  2280.    ;; Variables will have their contents inserted.  They should
  2281.    ;; contain strings, and will be inserted as strings.
  2282.    ((and (symbolp content) (boundp content))
  2283.     (ps-output-string (symbol-value content)))
  2284.  
  2285.    ;; Anything else will get turned into an empty string.
  2286.    (t
  2287.     (ps-output-string "")))
  2288.   (ps-output " ]\n"))
  2289.  
  2290. (defun ps-generate-header (name contents)
  2291.   (ps-output "/" name " [\n")
  2292.   (if (> ps-header-lines 0)
  2293.       (let ((count 1))
  2294.     (ps-generate-header-line "/h0" (car contents))
  2295.     (while (and (< count ps-header-lines)
  2296.             (setq contents (cdr contents)))
  2297.       (ps-generate-header-line "/h1" (car contents))
  2298.       (setq count (+ count 1)))
  2299.     (ps-output "] def\n"))))
  2300.  
  2301. (defun ps-output-boolean (name bool)
  2302.   (ps-output (format "/%s %s def\n" name (if bool "true" "false"))))
  2303.  
  2304. (defun ps-begin-file ()
  2305.   (ps-get-page-dimensions)
  2306.   (setq ps-showpage-count 0)
  2307.  
  2308.   (ps-output ps-adobe-tag)
  2309.   (ps-output "%%Title: " (buffer-name) "\n") ;Take job name from name of
  2310.                     ;first buffer printed
  2311.   (ps-output "%%Creator: " (user-full-name) "\n")
  2312.   (ps-output "%%CreationDate: " 
  2313.          (time-stamp-hh:mm:ss) " " (time-stamp-mon-dd-yyyy) "\n")
  2314.   (ps-output "%%Pages: (atend)\n")
  2315.   (ps-output "%%EndComments\n\n")
  2316.  
  2317.   (ps-output "%%BeginProlog\n")
  2318.   (ps-output-boolean "LandscapeMode"             ps-landscape-mode)
  2319.   (ps-output (format "/NumberOfColumns %d def\n" ps-number-of-columns))
  2320.  
  2321.   (ps-output (format "/LandscapePageHeight %s def\n" ps-landscape-page-height))
  2322.   (ps-output (format "/PrintWidth   %s def\n" ps-print-width))
  2323.   (ps-output (format "/PrintHeight  %s def\n" ps-print-height))
  2324.  
  2325.   (ps-output (format "/LeftMargin   %s def\n" ps-left-margin))
  2326.   (ps-output (format "/RightMargin  %s def\n" ps-right-margin)) ; not used
  2327.   (ps-output (format "/InterColumn  %s def\n" ps-inter-column))
  2328.  
  2329.   (ps-output (format "/BottomMargin %s def\n" ps-bottom-margin))
  2330.   (ps-output (format "/TopMargin    %s def\n" ps-top-margin)) ; not used
  2331.   (ps-output (format "/HeaderOffset %s def\n" ps-header-offset))
  2332.   (ps-output (format "/HeaderPad    %s def\n" ps-header-pad))
  2333.   
  2334.   (ps-output-boolean "PrintHeader"      ps-print-header)
  2335.   (ps-output-boolean "PrintHeaderFrame" ps-print-header-frame)
  2336.   (ps-output-boolean "ShowNofN"         ps-show-n-of-n)
  2337.   (ps-output-boolean "Duplex"           ps-spool-duplex)
  2338.  
  2339.   (ps-output (format "/LineHeight   %s def\n" ps-line-height))
  2340.  
  2341.   (ps-output ps-print-prologue-1)
  2342.   (ps-output "%%EndProlog\n\n")
  2343.  
  2344.  
  2345.   (ps-output "%%BeginSetup\n")
  2346.  
  2347.   ;; Header fonts
  2348.   (ps-output                ; /h0 14 /Helvetica-Bold Font
  2349.    (format "/h0 %s /%s DefFont\n" ps-header-title-font-size ps-header-title-font))
  2350.   (ps-output                ; /h1 12 /Helvetica Font
  2351.    (format "/h1 %s /%s DefFont\n" ps-header-font-size       ps-header-font))
  2352.  
  2353.   (ps-output ps-print-prologue-2)
  2354.  
  2355.   ;; Text fonts
  2356.   (ps-output (format "/f0 %s /%s DefFont\n" ps-font-size ps-font))
  2357.   (ps-output (format "/f1 %s /%s DefFont\n" ps-font-size ps-font-bold))
  2358.   (ps-output (format "/f2 %s /%s DefFont\n" ps-font-size ps-font-italic))
  2359.   (ps-output (format "/f3 %s /%s DefFont\n" ps-font-size ps-font-bold-italic))
  2360.  
  2361.   (ps-output "\nBeginDoc\n\n")
  2362.   (ps-output "%%EndSetup\n")
  2363. )
  2364.  
  2365. (defun ps-header-dirpart ()
  2366.   (let ((fname (buffer-file-name)))
  2367.     (if fname
  2368.     (if (string-equal (buffer-name) (file-name-nondirectory fname))
  2369.         (file-name-directory fname)
  2370.       fname)
  2371.       "")))
  2372.  
  2373. (defun ps-get-buffer-name ()
  2374.   (cond
  2375.    ;; Indulge Jim this little easter egg:
  2376.    ((string= (buffer-name) "ps-print.el")
  2377.     "Hey, Cool!  It's ps-print.el!!!")
  2378.    ;; Indulge Jack this other little easter egg:
  2379.    ((string= (buffer-name) "sokoban.el")
  2380.     "Super! C'est sokoban.el!")
  2381.    (t (buffer-name))))
  2382.  
  2383. (defun ps-begin-job ()
  2384.   (setq ps-page-count 0))
  2385.  
  2386. (defun ps-end-file ()
  2387.   (ps-output "\n\n%%Trailer\n")
  2388.   (ps-output (format "%%%%Pages: %d\n" (1+ (/ (1- ps-page-count)
  2389.                           ps-number-of-columns))))
  2390.   (ps-output "EndDoc\n")
  2391.   (ps-output "%%EOF\n"))
  2392.  
  2393. (defun ps-next-page ()
  2394.   (ps-end-page)
  2395.   (ps-flush-output)
  2396.   (ps-begin-page))
  2397.  
  2398. (defun ps-begin-page (&optional dummypage)
  2399.   (ps-get-page-dimensions)
  2400.   (setq ps-width-remaining  ps-print-width)
  2401.   (setq ps-height-remaining ps-print-height)
  2402.  
  2403.   ;; Print only when a new real page begins.
  2404.   (when (zerop (mod ps-page-count ps-number-of-columns))
  2405.     (ps-output (format "\n%%%%Page: %d %d\n"
  2406.                (1+ (/ ps-page-count ps-number-of-columns))
  2407.                (1+ (/ ps-page-count ps-number-of-columns)))))
  2408.  
  2409.   (ps-output "BeginDSCPage\n")
  2410.   (ps-output (format "/PageNumber %d def\n" (incf ps-page-count)))
  2411.   (ps-output "/PageCount 0 def\n")
  2412.  
  2413.   (when ps-print-header
  2414.     (ps-generate-header "HeaderLinesLeft"    ps-left-header)
  2415.     (ps-generate-header "HeaderLinesRight"   ps-right-header)
  2416.     (ps-output (format "%d SetHeaderLines\n" ps-header-lines)))
  2417.  
  2418.   (ps-output "BeginPage\n")
  2419.   (ps-set-font      ps-current-font)
  2420.   (ps-set-bg        ps-current-bg)
  2421.   (ps-set-color     ps-current-color)
  2422.   (ps-set-underline ps-current-underline-p))
  2423.  
  2424. (defun ps-end-page ()
  2425.   (setq ps-showpage-count (+ 1 ps-showpage-count))
  2426.   (ps-output "EndPage\n")
  2427.   (ps-output "EndDSCPage\n"))
  2428.  
  2429. (defun ps-dummy-page ()
  2430.   (setq ps-showpage-count (+ 1 ps-showpage-count))
  2431.   (ps-output "%%Page: " (format "- %d\n" ps-showpage-count)
  2432.          "BeginDSCPage
  2433. /PrintHeader false def
  2434. BeginPage
  2435. EndPage
  2436. EndDSCPage\n"))
  2437.         
  2438. (defun ps-next-line ()
  2439.   (if (< ps-height-remaining ps-line-height)
  2440.       (ps-next-page)
  2441.     (setq ps-width-remaining  ps-print-width)
  2442.     (setq ps-height-remaining (- ps-height-remaining ps-line-height))
  2443.     (ps-hard-lf)))
  2444.  
  2445. (defun ps-continue-line ()
  2446.   (if (< ps-height-remaining ps-line-height)
  2447.       (ps-next-page)
  2448.     (setq ps-width-remaining  ps-print-width)
  2449.     (setq ps-height-remaining (- ps-height-remaining ps-line-height))
  2450.     (ps-soft-lf)))
  2451.  
  2452. ;; [jack] Why hard and soft ?
  2453.  
  2454. (defun ps-hard-lf ()
  2455.   (ps-output "HL\n"))
  2456.  
  2457. (defun ps-soft-lf ()
  2458.   (ps-output "SL\n"))
  2459.  
  2460. (defun ps-find-wrappoint (from to char-width)
  2461.   (let ((avail (truncate (/ ps-width-remaining char-width)))
  2462.     (todo (- to from)))
  2463.     (if (< todo avail)
  2464.     (cons to (* todo char-width))
  2465.       (cons (+ from avail) ps-width-remaining))))
  2466.  
  2467. (defun ps-basic-plot-string (from to &optional bg-color)
  2468.   (let* ((wrappoint (ps-find-wrappoint from to ps-avg-char-width))
  2469.      (to (car wrappoint))
  2470.      (string (buffer-substring from to)))
  2471.     (ps-output-string string)
  2472.     (ps-output " S\n")
  2473.     wrappoint))
  2474.  
  2475. (defun ps-basic-plot-whitespace (from to &optional bg-color)
  2476.   (let* ((wrappoint (ps-find-wrappoint from to ps-space-width))
  2477.      (to (car wrappoint)))
  2478.  
  2479.     (ps-output (format "%d W\n" (- to from)))
  2480.     wrappoint))
  2481.  
  2482. (defun ps-plot (plotfunc from to &optional bg-color)
  2483.   (while (< from to)
  2484.     (let* ((wrappoint (funcall plotfunc from to bg-color))
  2485.        (plotted-to (car wrappoint))
  2486.        (plotted-width (cdr wrappoint)))
  2487.       (setq from plotted-to)
  2488.       (setq ps-width-remaining (- ps-width-remaining plotted-width))
  2489.       (if (< from to)
  2490.       (ps-continue-line))))
  2491.   (if ps-razzle-dazzle
  2492.       (let* ((q-todo (- (point-max) (point-min)))
  2493.          (q-done (- (point) (point-min)))
  2494.          (chunkfrac (/ q-todo 8))
  2495.          (chunksize (if (> chunkfrac 1000) 1000 chunkfrac)))
  2496.     (if (> (- q-done ps-razchunk) chunksize)
  2497.         (let (foo)
  2498.           (setq ps-razchunk q-done)
  2499.           (setq foo
  2500.             (if (< q-todo 100)
  2501.             (/ (* 100 q-done) q-todo)
  2502.               (/ q-done (/ q-todo 100))))
  2503.           (message "Formatting...%3d%%" foo))))))
  2504.  
  2505. (defun ps-set-font (font)
  2506.   (setq ps-current-font font)
  2507.   (ps-output (format "/f%d F\n" ps-current-font)))
  2508.  
  2509. (defun ps-set-bg (color)
  2510.   (if (setq ps-current-bg color)
  2511.       (ps-output (format ps-color-format (nth 0 color) (nth 1 color)
  2512.              (nth 2 color))
  2513.          " true BG\n")
  2514.     (ps-output "false BG\n")))
  2515.  
  2516. (defun ps-set-color (color)
  2517.   (if (setq ps-current-color color)
  2518.       nil
  2519.     (setq ps-current-color ps-default-fg))
  2520.   (ps-output (format ps-color-format (nth 0 ps-current-color)
  2521.              (nth 1 ps-current-color) (nth 2 ps-current-color))
  2522.          " FG\n"))
  2523.  
  2524. (defun ps-set-underline (underline-p)
  2525.   (ps-output (if underline-p "true" "false") " UL\n")
  2526.   (setq ps-current-underline-p underline-p))
  2527.  
  2528. (defun ps-plot-region (from to font fg-color &optional bg-color underline-p)
  2529.  
  2530.   (if (not (equal font ps-current-font))
  2531.       (ps-set-font font))
  2532.   
  2533.   ;; Specify a foreground color only if one's specified and it's
  2534.   ;; different than the current.
  2535.   (if (not (equal fg-color ps-current-color))
  2536.       (ps-set-color fg-color))
  2537.   
  2538.   (if (not (equal bg-color ps-current-bg))
  2539.       (ps-set-bg bg-color))
  2540.   
  2541.   ;; Toggle underlining if different.
  2542.   (if (not (equal underline-p ps-current-underline-p))
  2543.       (ps-set-underline underline-p))
  2544.  
  2545.   ;; Starting at the beginning of the specified region...
  2546.   (save-excursion
  2547.     (goto-char from)
  2548.  
  2549.     ;; ...break the region up into chunks separated by tabs, linefeeds,
  2550.     ;; and pagefeeds, and plot each chunk.
  2551.     (while (< from to)
  2552.       (if (re-search-forward "[\t\n\f]" to t)
  2553.           (let ((match (char-after (match-beginning 0))))
  2554.             (cond
  2555.          ((= match ?\t)
  2556.           (let ((linestart
  2557.              (save-excursion (beginning-of-line) (point))))
  2558.         (ps-plot 'ps-basic-plot-string from (- (point) 1)
  2559.              bg-color)
  2560.         (forward-char -1)
  2561.         (setq from (+ linestart (current-column)))
  2562.         (if (re-search-forward "[ \t]+" to t)
  2563.             (ps-plot 'ps-basic-plot-whitespace
  2564.                  from (+ linestart (current-column))
  2565.                  bg-color))))
  2566.  
  2567.          ((= match ?\n)
  2568.           (ps-plot 'ps-basic-plot-string from (- (point) 1)
  2569.                bg-color)
  2570.           (ps-next-line)
  2571.           )
  2572.  
  2573.          ((= match ?\f)
  2574.           (ps-plot 'ps-basic-plot-string from (- (point) 1)
  2575.                bg-color)
  2576.           (ps-next-page)))
  2577.             (setq from (point)))
  2578.         (ps-plot 'ps-basic-plot-string from to bg-color)
  2579.         (setq from to)))))
  2580.  
  2581. (defun ps-color-value (x-color-value)
  2582.   ;; Scale 16-bit X-COLOR-VALUE to PostScript color value in [0, 1] interval.
  2583.   (/ x-color-value ps-print-color-scale))
  2584.  
  2585. (defun ps-color-values (x-color)
  2586.   (cond ((fboundp 'color-instance-rgb-components)
  2587.      (if (ps-color-device)
  2588.          (color-instance-rgb-components
  2589.           (if (color-instance-p x-color) x-color
  2590.         (if (color-specifier-p x-color)
  2591.             (make-color-instance (color-name x-color))
  2592.           (make-color-instance x-color))))
  2593.        (error "No available function to determine X color values.")))
  2594.     ((fboundp 'x-color-values)
  2595.      (x-color-values x-color))
  2596.     (t (error "No available function to determine X color values."))))
  2597.  
  2598. ;; This function rewritten for XEmacs so that colors are compared
  2599. ;; properly.
  2600. ;;
  2601. ;;(defun ps-face-attributes (face)
  2602. ;;  (let ((differs (face-differs-from-default-p face)))
  2603. ;;    (list (memq face ps-ref-bold-faces)
  2604. ;;      (memq face ps-ref-italic-faces)
  2605. ;;      (memq face ps-ref-underlined-faces)
  2606. ;;      (and differs (face-foreground face))
  2607. ;;      (and differs (face-background face)))))
  2608.  
  2609. (defun ps-face-attributes (face)
  2610.   (list (memq face ps-ref-bold-faces)
  2611.     (memq face ps-ref-italic-faces)
  2612.     (memq face ps-ref-underlined-faces)
  2613.     (and (not (equal (color-name (face-foreground 'default))
  2614.              (color-name (face-foreground face))))
  2615.          (face-foreground face))
  2616.     (and (not (equal (color-name (face-background 'default))
  2617.              (color-name (face-background face))))
  2618.          (face-background face))))
  2619.  
  2620. (defun ps-face-attribute-list (face-or-list)
  2621.   (if (listp face-or-list)
  2622.       (let (bold-p italic-p underline-p foreground background face-attr face)
  2623.     (while face-or-list
  2624.       (setq face (car face-or-list))
  2625.       (setq face-attr (ps-face-attributes face))
  2626.       (setq bold-p (or bold-p (nth 0 face-attr)))
  2627.       (setq italic-p (or italic-p (nth 1 face-attr)))
  2628.       (setq underline-p (or underline-p (nth 2 face-attr)))
  2629.       (if foreground
  2630.           nil
  2631.         (setq foreground (nth 3 face-attr)))
  2632.       (if background
  2633.           nil
  2634.         (setq background (nth 4 face-attr)))
  2635.       (setq face-or-list (cdr face-or-list)))
  2636.     (list bold-p italic-p underline-p foreground background))
  2637.  
  2638.     (ps-face-attributes face-or-list)))
  2639.  
  2640. (defun ps-plot-with-face (from to face)
  2641.   (if face
  2642.       (let* ((face-attr (ps-face-attribute-list face))
  2643.          (bold-p (nth 0 face-attr))
  2644.          (italic-p (nth 1 face-attr))
  2645.          (underline-p (nth 2 face-attr))
  2646.          (foreground (nth 3 face-attr))
  2647.          (background (nth 4 face-attr))
  2648.          (fg-color (if (and ps-print-color-p
  2649.                 (ps-color-device) 
  2650.                 foreground)
  2651.                (mapcar 'ps-color-value
  2652.                    (ps-color-values foreground))
  2653.              ps-default-color))
  2654.          (bg-color (if (and ps-print-color-p
  2655.                 (ps-color-device)
  2656.                 background)
  2657.                (mapcar 'ps-color-value
  2658.                    (ps-color-values background)))))
  2659.     (ps-plot-region from to
  2660.             (cond ((and bold-p italic-p) 3)
  2661.                   (italic-p 2)
  2662.                   (bold-p 1)
  2663.                   (t 0))
  2664. ;            (or fg-color '(0.0 0.0 0.0))
  2665.             fg-color
  2666.             bg-color underline-p))
  2667.     (goto-char to)))
  2668.  
  2669.  
  2670. (defun ps-emacs-face-kind-p (face kind kind-regex kind-list)
  2671.   (let ((frame-font (face-font face))
  2672.     (face-defaults (face-font face t)))
  2673.     (or
  2674.      ;; Check FACE defaults:
  2675.      (and (listp face-defaults)
  2676.       (memq kind face-defaults))
  2677.  
  2678.      ;; Check the user's preferences
  2679.      (memq face kind-list))))
  2680.  
  2681. (defun ps-xemacs-face-kind-p (face kind kind-regex kind-list)
  2682.   (let* ((frame-font
  2683.       (or (face-font-instance face) (face-font-instance 'default)))
  2684.      (kind-cons (and frame-font
  2685.              (assq kind (font-instance-properties frame-font))))
  2686.      (kind-spec (cdr-safe kind-cons))
  2687.      (case-fold-search t))
  2688.  
  2689.     (or (and kind-spec (string-match kind-regex kind-spec))
  2690.     ;; Kludge-compatible:
  2691.     (memq face kind-list))))
  2692.  
  2693. (defun ps-face-bold-p (face)
  2694.   (if (eq ps-print-emacs-type 'emacs)
  2695.       (ps-emacs-face-kind-p face 'bold "-\\(bold\\|demibold\\)-"
  2696.               ps-bold-faces)
  2697.     (ps-xemacs-face-kind-p face 'WEIGHT_NAME "bold\\|demibold"
  2698.                ps-bold-faces)))
  2699.  
  2700. (defun ps-face-italic-p (face)
  2701.   (if (eq ps-print-emacs-type 'emacs)
  2702.       (ps-emacs-face-kind-p face 'italic "-[io]-" ps-italic-faces)
  2703.     (or
  2704.      (ps-xemacs-face-kind-p face 'ANGLE_NAME "i\\|o" ps-italic-faces)
  2705.      (ps-xemacs-face-kind-p face 'SLANT "i\\|o" ps-italic-faces))))
  2706.  
  2707. (defun ps-face-underlined-p (face)
  2708.   (or (face-underline-p face)
  2709.       (memq face ps-underlined-faces)))
  2710.  
  2711. ;; Ensure that face-list is fbound.
  2712. (or (fboundp 'face-list) (defalias 'face-list 'list-faces))
  2713.  
  2714. (defun ps-build-reference-face-lists ()
  2715.   (if ps-auto-font-detect
  2716.       (let ((faces (if (eq ps-print-emacs-type 'xemacs)
  2717.                (face-list 5)
  2718.              (face-list)))
  2719.         the-face)
  2720.     (setq ps-ref-bold-faces nil
  2721.           ps-ref-italic-faces nil
  2722.           ps-ref-underlined-faces nil)
  2723.     (while faces
  2724.       (setq the-face (car faces))
  2725.       (if (ps-face-italic-p the-face)
  2726.           (setq ps-ref-italic-faces
  2727.             (cons the-face ps-ref-italic-faces)))
  2728.       (if (ps-face-bold-p the-face)
  2729.           (setq ps-ref-bold-faces
  2730.             (cons the-face ps-ref-bold-faces)))
  2731.       (if (ps-face-underlined-p the-face)
  2732.           (setq ps-ref-underlined-faces
  2733.             (cons the-face ps-ref-underlined-faces)))
  2734.       (setq faces (cdr faces))))
  2735.     (setq ps-ref-bold-faces ps-bold-faces)
  2736.     (setq ps-ref-italic-faces ps-italic-faces)
  2737.     (setq ps-ref-underlined-faces ps-underlined-faces))
  2738.   (setq ps-build-face-reference nil))
  2739.  
  2740. (defun ps-mapper (extent list)
  2741.   (nconc list (list (list (extent-start-position extent) 'push extent)
  2742.                     (list (extent-end-position extent) 'pull extent)))
  2743.   nil)
  2744.  
  2745. (defun ps-extent-sorter (a b)
  2746.   (< (extent-priority a) (extent-priority b)))
  2747.  
  2748. (defun ps-print-ensure-fontified (start end)
  2749.   (if (and (boundp 'lazy-lock-mode) lazy-lock-mode)
  2750.       (if (fboundp 'lazy-lock-fontify-region)
  2751.           (lazy-lock-fontify-region start end) ; the new
  2752.         (lazy-lock-fontify-buffer)))           ; the old
  2753.   (if (and (boundp 'lazy-shot-mode) lazy-shot-mode) ;; temporary untill
  2754.       (lazy-shot-fontify-region start end)))        ;;  lazy-shot is renamed
  2755.   
  2756.  
  2757. (defun ps-generate-postscript-with-faces (from to)
  2758.   ;; Build the reference lists of faces if necessary.
  2759.   (if (or ps-always-build-face-reference
  2760.       ps-build-face-reference)
  2761.       (progn
  2762.     (message "Collecting face information...")
  2763.     (ps-build-reference-face-lists)))
  2764.   ;; Set the color scale.  We do it here instead of in the defvar so
  2765.   ;; that ps-print can be dumped into emacs.  This expression can't be
  2766.   ;; evaluated at dump-time because X isn't initialized.
  2767.   (setq ps-print-color-scale
  2768.     (if (and ps-print-color-p (ps-color-device))
  2769.         (float (car (ps-color-values "white")))
  2770.       1.0))
  2771.   ;; Generate some PostScript.
  2772.   (save-restriction
  2773.     (narrow-to-region from to)
  2774.     (let ((face 'default)
  2775.       (position to))
  2776.       (ps-print-ensure-fontified from to)
  2777.       (cond ((or (eq ps-print-emacs-type 'lucid)
  2778.          (eq ps-print-emacs-type 'xemacs))
  2779.        ;; Build the list of extents...
  2780.        (let ((a (cons 'dummy nil))
  2781.          record type extent extent-list)
  2782.          (map-extents 'ps-mapper nil from to a)
  2783.          (setq a (sort (cdr a) 'car-less-than-car))
  2784.        
  2785.          (setq extent-list nil)
  2786.        
  2787.          ;; Loop through the extents...
  2788.          (while a
  2789.            (setq record (car a))
  2790.          
  2791.            (setq position (car record))
  2792.            (setq record (cdr record))
  2793.          
  2794.            (setq type (car record))
  2795.            (setq record (cdr record))
  2796.          
  2797.            (setq extent (car record))
  2798.          
  2799.            ;; Plot up to this record.
  2800.            ;; XEmacs 19.12: for some reason, we're getting into a
  2801.            ;; situation in which some of the records have
  2802.            ;; positions less than 'from'.  Since we've narrowed
  2803.            ;; the buffer, this'll generate errors.  This is a
  2804.            ;; hack, but don't call ps-plot-with-face unless from >
  2805.            ;; point-min.
  2806.            (if (and (>= from (point-min))
  2807.             (<= position (point-max)))
  2808.            (ps-plot-with-face from position face))
  2809.          
  2810.            (cond
  2811.         ((eq type 'push)
  2812.          (if (extent-face extent)
  2813.              (setq   extent-list (sort (cons extent extent-list)
  2814.                            'ps-extent-sorter))))
  2815.           
  2816.         ((eq type 'pull)
  2817.          (setq extent-list (sort (delq extent extent-list)
  2818.                      'ps-extent-sorter))))
  2819.          
  2820.            (setq face
  2821.              (if extent-list
  2822.              (extent-face (car extent-list))
  2823.                'default))
  2824.          
  2825.            (setq from position)
  2826.            (setq a (cdr a)))))
  2827.  
  2828.         ((eq ps-print-emacs-type 'emacs)
  2829.          (let ((property-change from)
  2830.            (overlay-change from))
  2831.            (while (< from to)
  2832.          (if (< property-change to) ; Don't search for property change
  2833.                     ; unless previous search succeeded.
  2834.              (setq property-change
  2835.                (next-property-change from nil to)))
  2836.          (if (< overlay-change to) ; Don't search for overlay change
  2837.                     ; unless previous search succeeded.
  2838.              (setq overlay-change
  2839.                (min (next-overlay-change from) to)))
  2840.          (setq position
  2841.                (min property-change overlay-change))
  2842.          ;; The code below is not quite correct,
  2843.          ;; because a non-nil overlay invisible property
  2844.          ;; which is inactive according to the current value
  2845.          ;; of buffer-invisibility-spec nonetheless overrides
  2846.          ;; a face text property.
  2847.          (setq face
  2848.                (cond ((let ((prop (get-text-property from 'invisible)))
  2849.                 ;; Decide whether this invisible property
  2850.                 ;; really makes the text invisible.
  2851.                 (if (eq buffer-invisibility-spec t)
  2852.                     (not (null prop))
  2853.                   (or (memq prop buffer-invisibility-spec)
  2854.                       (assq prop buffer-invisibility-spec))))
  2855.                   nil)
  2856.                  ((get-text-property from 'face))
  2857.                  (t 'default)))
  2858.          (let ((overlays (overlays-at from))
  2859.                (face-priority -1)) ; text-property
  2860.            (while overlays
  2861.              (let* ((overlay (car overlays))
  2862.                 (overlay-face (overlay-get overlay 'face))
  2863.                 (overlay-invisible (overlay-get overlay 'invisible))
  2864.                 (overlay-priority (or (overlay-get overlay
  2865.                                    'priority)
  2866.                           0)))
  2867.                (if (and (or overlay-invisible overlay-face)
  2868.                 (> overlay-priority face-priority))
  2869.                (setq face (cond ((if (eq buffer-invisibility-spec t)
  2870.                          (not (null overlay-invisible))
  2871.                            (or (memq overlay-invisible buffer-invisibility-spec)
  2872.                            (assq overlay-invisible buffer-invisibility-spec)))
  2873.                          nil)
  2874.                         ((and face overlay-face)))
  2875.                  face-priority overlay-priority)))
  2876.              (setq overlays (cdr overlays))))
  2877.          ;; Plot up to this record.
  2878.          (ps-plot-with-face from position face)
  2879.          (setq from position)))))
  2880.       (ps-plot-with-face from to face))))  
  2881.  
  2882. (defun ps-generate-postscript (from to)
  2883.   (ps-plot-region from to 0 nil))
  2884.  
  2885. (defun ps-generate (buffer from to genfunc)
  2886.   (let ((from (min to from))
  2887.     (to (max to from))
  2888.     ;; This avoids trouble if chars with read-only properties
  2889.     ;; are copied into ps-spool-buffer.
  2890.     (inhibit-read-only t))
  2891.     (save-restriction
  2892.       (narrow-to-region from to)
  2893.       (if ps-razzle-dazzle
  2894.       (message "Formatting...%3d%%" (setq ps-razchunk 0)))
  2895.       (set-buffer buffer)
  2896.       (setq ps-source-buffer buffer)
  2897.       (setq ps-spool-buffer (get-buffer-create ps-spool-buffer-name))
  2898.       (ps-init-output-queue)
  2899.       (let (safe-marker completed-safely needs-begin-file)
  2900.     (unwind-protect
  2901.         (progn
  2902.           (set-buffer ps-spool-buffer)
  2903.         
  2904.           ;; Get a marker and make it point to the current end of the
  2905.           ;; buffer,  If an error occurs, we'll delete everything from
  2906.           ;; the end of this marker onwards.
  2907.           (setq safe-marker (make-marker))
  2908.           (set-marker safe-marker (point-max))
  2909.         
  2910.           (goto-char (point-min))
  2911.           (if (looking-at (regexp-quote ps-adobe-tag))
  2912.           nil
  2913.         (setq needs-begin-file t))
  2914.           (save-excursion
  2915.         (set-buffer ps-source-buffer)
  2916.         (if needs-begin-file (ps-begin-file))
  2917.         (ps-begin-job)
  2918.         (ps-begin-page))
  2919.           (set-buffer ps-source-buffer)
  2920.           (funcall genfunc from to)
  2921.           (ps-end-page)
  2922.         
  2923.           (if (and ps-spool-duplex
  2924.                (= (mod ps-page-count 2) 1))
  2925.           (ps-dummy-page))
  2926.           (ps-flush-output)
  2927.         
  2928.           ;; Back to the PS output buffer to set the page count
  2929.           (set-buffer ps-spool-buffer)
  2930.           (goto-char (point-max))
  2931.           (while (re-search-backward "^/PageCount 0 def$" nil t)
  2932.         (replace-match (format "/PageCount %d def" ps-page-count) t))
  2933.  
  2934.           ;; Setting this variable tells the unwind form that
  2935.           ;; the postscript was generated without error.
  2936.           (setq completed-safely t))
  2937.  
  2938.       ;; Unwind form: If some bad mojo occurred while generating
  2939.       ;; postscript, delete all the postscript that was generated.
  2940.       ;; This protects the previously spooled files from getting
  2941.       ;; corrupted.
  2942.       (if (and (markerp safe-marker) (not completed-safely))
  2943.           (progn
  2944.         (set-buffer ps-spool-buffer)
  2945.         (delete-region (marker-position safe-marker) (point-max))))))
  2946.  
  2947.       (if ps-razzle-dazzle
  2948.       (message "Formatting...done")))))
  2949.  
  2950. ;; Permit dynamic evaluation at print time of ps-lpr-switches
  2951. (defun ps-do-despool (filename)
  2952.   (if (or (not (boundp 'ps-spool-buffer))
  2953.       (not (symbol-value 'ps-spool-buffer)))
  2954.       (message "No spooled PostScript to print")
  2955.     (ps-end-file)
  2956.     (ps-flush-output)
  2957.     (if filename
  2958.     (save-excursion
  2959.       (if ps-razzle-dazzle
  2960.           (message "Saving..."))
  2961.       (set-buffer ps-spool-buffer)
  2962.       (setq filename (expand-file-name filename))
  2963.       (write-region (point-min) (point-max) filename)
  2964.       (if ps-razzle-dazzle
  2965.           (message "Wrote %s" filename)))
  2966.       ;; Else, spool to the printer
  2967.       (if ps-razzle-dazzle
  2968.       (message "Printing..."))
  2969.       (save-excursion
  2970.     (set-buffer ps-spool-buffer)
  2971.     (if (and (eq system-type 'ms-dos) (stringp dos-ps-printer))
  2972.         (write-region (point-min) (point-max) dos-ps-printer t 0)
  2973.       (let ((binary-process-input t)  ; for MS-DOS
  2974.         (ps-lpr-sw ; Dynamic evaluation
  2975.          (ps-flatten-list (mapcar 'ps-eval-switch ps-lpr-switches))))
  2976.         (apply 'call-process-region
  2977.            (point-min) (point-max) ps-lpr-command nil
  2978.            (if (fboundp 'start-process) 0 nil)
  2979.            nil
  2980.            ps-lpr-sw))))
  2981.       (if ps-razzle-dazzle
  2982.       (message "Printing...done")))
  2983.     (kill-buffer ps-spool-buffer)))
  2984.  
  2985. ;; Dynamic evaluation
  2986. (defun ps-eval-switch (arg)
  2987.   (cond ((stringp arg) arg)
  2988.     ((functionp arg) (apply arg nil))
  2989.     ((symbolp arg) (symbol-value arg))
  2990.     ((consp arg) (apply (car arg) (cdr arg)))
  2991.     (t nil)))
  2992.  
  2993. ;; `ps-flatten-list' is defined here (copied from "message.el" and
  2994. ;; enhanced to handle dotted pairs as well) until we can get some
  2995. ;; sensible autoloads, or `flatten-list' gets put somewhere decent.
  2996.  
  2997. ;; (ps-flatten-list '((a . b) c (d . e) (f g h) i . j))
  2998. ;; => (a b c d e f g h i j)
  2999.  
  3000. (defun ps-flatten-list (&rest list)
  3001.   (ps-flatten-list-1 list))
  3002.  
  3003. (defun ps-flatten-list-1 (list)
  3004.   (cond
  3005.     ((null list) (list))
  3006.     ((consp list)
  3007.      (append (ps-flatten-list-1 (car list))
  3008.          (ps-flatten-list-1 (cdr list))))
  3009.     (t (list list))))
  3010.  
  3011. (defun ps-kill-emacs-check ()
  3012.   (let (ps-buffer)
  3013.     (if (and (setq ps-buffer (get-buffer ps-spool-buffer-name))
  3014.          (buffer-modified-p ps-buffer))
  3015.     (if (y-or-n-p "Unprinted PostScript waiting; print now? ")
  3016.         (ps-despool)))
  3017.     (if (and (setq ps-buffer (get-buffer ps-spool-buffer-name))
  3018.          (buffer-modified-p ps-buffer))
  3019.     (if (yes-or-no-p "Unprinted PostScript waiting; exit anyway? ")
  3020.         nil
  3021.       (error "Unprinted PostScript")))))
  3022.  
  3023. (if (fboundp 'add-hook)
  3024.     (add-hook 'kill-emacs-hook 'ps-kill-emacs-check)
  3025.   (if kill-emacs-hook
  3026.       (message "Won't override existing kill-emacs-hook")
  3027.     (setq kill-emacs-hook 'ps-kill-emacs-check)))
  3028.  
  3029. ;;; Sample Setup Code:
  3030.  
  3031. ;; This stuff is for anybody that's brave enough to look this far,
  3032. ;; and able to figure out how to use it.  It isn't really part of ps-
  3033. ;; print, but I'll leave it here in hopes it might be useful:
  3034.  
  3035. ;; WARNING!!! The following code is *sample* code only. Don't use it
  3036. ;; unless you understand what it does!
  3037.  
  3038. (defmacro ps-prsc () (list 'if (list 'eq 'ps-print-emacs-type ''emacs)
  3039.                [f22] ''f22))
  3040. (defmacro ps-c-prsc () (list 'if (list 'eq 'ps-print-emacs-type ''emacs)
  3041.                  [C-f22]
  3042.                  ''(control f22)))
  3043. (defmacro ps-s-prsc () (list 'if (list 'eq 'ps-print-emacs-type ''emacs)
  3044.                  [S-f22]
  3045.                  ''(shift f22)))
  3046.  
  3047. ;; Look in an article or mail message for the Subject: line.  To be
  3048. ;; placed in ps-left-headers.
  3049. (defun ps-article-subject ()
  3050.   (save-excursion
  3051.     (goto-char (point-min))
  3052.     (if (re-search-forward "^Subject:[ \t]+\\(.*\\)$" nil t)
  3053.     (buffer-substring (match-beginning 1) (match-end 1))
  3054.       "Subject ???")))
  3055.  
  3056. ;; Look in an article or mail message for the From: line.  Sorta-kinda
  3057. ;; understands RFC-822 addresses and can pull the real name out where
  3058. ;; it's provided.  To be placed in ps-left-headers.
  3059. (defun ps-article-author ()
  3060.   (save-excursion
  3061.     (goto-char (point-min))
  3062.     (if (re-search-forward "^From:[ \t]+\\(.*\\)$" nil t)
  3063.     (let ((fromstring (buffer-substring (match-beginning 1) (match-end 1))))
  3064.       (cond
  3065.  
  3066.        ;; Try first to match addresses that look like
  3067.        ;; thompson@wg2.waii.com (Jim Thompson)
  3068.        ((string-match ".*[ \t]+(\\(.*\\))" fromstring)
  3069.         (substring fromstring (match-beginning 1) (match-end 1)))
  3070.  
  3071.        ;; Next try to match addresses that look like
  3072.        ;; Jim Thompson <thompson@wg2.waii.com>
  3073.        ((string-match "\\(.*\\)[ \t]+<.*>" fromstring)
  3074.         (substring fromstring (match-beginning 1) (match-end 1)))
  3075.  
  3076.        ;; Couldn't find a real name -- show the address instead.
  3077.        (t fromstring)))
  3078.       "From ???")))
  3079.  
  3080. ;; A hook to bind to gnus-Article-prepare-hook.  This will set the ps-
  3081. ;; left-headers specially for gnus articles.  Unfortunately, gnus-
  3082. ;; article-mode-hook is called only once, the first time the *Article*
  3083. ;; buffer enters that mode, so it would only work for the first time
  3084. ;; we ran gnus.  The second time, this hook wouldn't get set up.  The
  3085. ;; only alternative is gnus-article-prepare-hook.
  3086. (defun ps-gnus-article-prepare-hook ()
  3087.   (setq ps-header-lines 3)
  3088.   (setq ps-left-header
  3089.     ;; The left headers will display the article's subject, its
  3090.     ;; author, and the newsgroup it was in.
  3091.     (list 'ps-article-subject 'ps-article-author 'gnus-newsgroup-name)))
  3092.  
  3093. ;; A hook to bind to vm-mode-hook to locally bind prsc and set the ps-
  3094. ;; left-headers specially for mail messages.  This header setup would
  3095. ;; also work, I think, for RMAIL.
  3096. (defun ps-vm-mode-hook ()
  3097.   (local-set-key (ps-prsc) 'ps-vm-print-message-from-summary)
  3098.   (setq ps-header-lines 3)
  3099.   (setq ps-left-header
  3100.     ;; The left headers will display the message's subject, its
  3101.     ;; author, and the name of the folder it was in.
  3102.     (list 'ps-article-subject 'ps-article-author 'buffer-name)))
  3103.  
  3104. ;; Every now and then I forget to switch from the *Summary* buffer to
  3105. ;; the *Article* before hitting prsc, and a nicely formatted list of
  3106. ;; article subjects shows up at the printer.  This function, bound to
  3107. ;; prsc for the gnus *Summary* buffer means I don't have to switch
  3108. ;; buffers first.
  3109. ;; sb:  Updated for Gnus 5.
  3110. (defun ps-gnus-print-article-from-summary ()
  3111.   (interactive)
  3112.   (let ((ps-buf (if (boundp 'gnus-article-buffer)
  3113.             gnus-article-buffer
  3114.           "*Article*")))
  3115.     (if (get-buffer ps-buf)
  3116.     (save-excursion
  3117.       (set-buffer ps-buf)
  3118.       (ps-spool-buffer-with-faces)))))
  3119.  
  3120. ;; See ps-gnus-print-article-from-summary.  This function does the
  3121. ;; same thing for vm.
  3122. (defun ps-vm-print-message-from-summary ()
  3123.   (interactive)
  3124.   (if (and (boundp 'vm-mail-buffer) (symbol-value 'vm-mail-buffer))
  3125.       (save-excursion
  3126.     (set-buffer (symbol-value 'vm-mail-buffer))
  3127.     (ps-spool-buffer-with-faces))))
  3128.  
  3129. ;; A hook to bind to bind to gnus-summary-setup-buffer to locally bind
  3130. ;; prsc.
  3131. (defun ps-gnus-summary-setup ()
  3132.   (local-set-key (ps-prsc) 'ps-gnus-print-article-from-summary))
  3133.  
  3134. ;; Look in an article or mail message for the Subject: line.  To be
  3135. ;; placed in ps-left-headers.
  3136. (defun ps-info-file ()
  3137.   (save-excursion
  3138.     (goto-char (point-min))
  3139.     (if (re-search-forward "File:[ \t]+\\([^, \t\n]*\\)" nil t)
  3140.     (buffer-substring (match-beginning 1) (match-end 1))
  3141.       "File ???")))
  3142.  
  3143. ;; Look in an article or mail message for the Subject: line.  To be
  3144. ;; placed in ps-left-headers.
  3145. (defun ps-info-node ()
  3146.   (save-excursion
  3147.     (goto-char (point-min))
  3148.     (if (re-search-forward "Node:[ \t]+\\([^,\t\n]*\\)" nil t)
  3149.     (buffer-substring (match-beginning 1) (match-end 1))
  3150.       "Node ???")))
  3151.  
  3152. (defun ps-info-mode-hook ()
  3153.   (setq ps-left-header
  3154.     ;; The left headers will display the node name and file name.
  3155.     (list 'ps-info-node 'ps-info-file)))
  3156.  
  3157. ;; WARNING! The following function is a *sample* only, and is *not*
  3158. ;; meant to be used as a whole unless you understand what the effects
  3159. ;; will be!  (In fact, this is a copy of Jim's setup for ps-print --
  3160. ;; I'd be very surprised if it was useful to *anybody*, without
  3161. ;; modification.)
  3162.  
  3163. (defun ps-jts-ps-setup ()
  3164.   (global-set-key (ps-prsc) 'ps-spool-buffer-with-faces) ;f22 is prsc
  3165.   (global-set-key (ps-s-prsc) 'ps-spool-region-with-faces)
  3166.   (global-set-key (ps-c-prsc) 'ps-despool)
  3167.   (add-hook 'gnus-article-prepare-hook 'ps-gnus-article-prepare-hook)
  3168.   (add-hook 'gnus-summary-mode-hook 'ps-gnus-summary-setup)
  3169.   (add-hook 'vm-mode-hook 'ps-vm-mode-hook)
  3170.   (add-hook 'vm-mode-hooks 'ps-vm-mode-hook)
  3171.   (add-hook 'Info-mode-hook 'ps-info-mode-hook)
  3172.   (setq ps-spool-duplex t)
  3173.   (setq ps-print-color-p nil)
  3174.   (setq ps-lpr-command "lpr")
  3175.   (setq ps-lpr-switches '("-Jjct,duplex_long"))
  3176.   'ps-jts-ps-setup)
  3177.  
  3178. ;; WARNING! The following function is a *sample* only, and is *not*
  3179. ;; meant to be used as a whole unless it corresponds to your needs.
  3180. ;; (In fact, this is a copy of Jack's setup for ps-print --
  3181. ;; I would not be that surprised if it was useful to *anybody*,
  3182. ;; without modification.)
  3183.  
  3184. (defun ps-jack-setup ()
  3185.   (setq ps-print-color-p  'nil
  3186.     ps-lpr-command    "lpr"
  3187.     ps-lpr-switches   (list)
  3188.  
  3189.     ps-paper-type       'a4
  3190.     ps-landscape-mode   't
  3191.     ps-number-of-columns 2
  3192.  
  3193.     ps-left-margin   (/ (* 72  1.0) 2.54) ;  1.0 cm
  3194.     ps-right-margin  (/ (* 72  1.0) 2.54) ;  1.0 cm
  3195.     ps-inter-column  (/ (* 72  1.0) 2.54) ;  1.0 cm
  3196.     ps-bottom-margin (/ (* 72  1.5) 2.54) ;  1.5 cm
  3197.     ps-top-margin    (/ (* 72  1.5) 2.54) ;  1.5 cm
  3198.     ps-header-offset (/ (* 72  1.0) 2.54) ;  1.0 cm
  3199.     ps-header-line-pad    .15
  3200.     ps-print-header       t
  3201.     ps-print-header-frame t
  3202.     ps-header-lines       2
  3203.     ps-show-n-of-n        t
  3204.     ps-spool-duplex       nil
  3205.  
  3206.     ps-font-family             'Courier
  3207.     ps-font-size               5.5
  3208.     ps-header-font-family      'Helvetica
  3209.     ps-header-font-size        6
  3210.     ps-header-title-font-size  8)
  3211.   'ps-jack-setup)
  3212.  
  3213. (provide 'ps-print)
  3214.  
  3215. ;;; ps-print.el ends here
  3216.